htt_tx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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, bool limit_mgmt_desc)
  24. {
  25. if (limit_mgmt_desc)
  26. htt->num_pending_mgmt_tx--;
  27. htt->num_pending_tx--;
  28. if (htt->num_pending_tx == htt->max_num_pending_tx - 1)
  29. ath10k_mac_tx_unlock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
  30. }
  31. static void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt,
  32. bool limit_mgmt_desc)
  33. {
  34. spin_lock_bh(&htt->tx_lock);
  35. __ath10k_htt_tx_dec_pending(htt, limit_mgmt_desc);
  36. spin_unlock_bh(&htt->tx_lock);
  37. }
  38. static int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt,
  39. bool limit_mgmt_desc, bool is_probe_resp)
  40. {
  41. struct ath10k *ar = htt->ar;
  42. int ret = 0;
  43. spin_lock_bh(&htt->tx_lock);
  44. if (htt->num_pending_tx >= htt->max_num_pending_tx) {
  45. ret = -EBUSY;
  46. goto exit;
  47. }
  48. if (limit_mgmt_desc) {
  49. if (is_probe_resp && (htt->num_pending_mgmt_tx >
  50. ar->hw_params.max_probe_resp_desc_thres)) {
  51. ret = -EBUSY;
  52. goto exit;
  53. }
  54. htt->num_pending_mgmt_tx++;
  55. }
  56. htt->num_pending_tx++;
  57. if (htt->num_pending_tx == htt->max_num_pending_tx)
  58. ath10k_mac_tx_lock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
  59. exit:
  60. spin_unlock_bh(&htt->tx_lock);
  61. return ret;
  62. }
  63. int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *skb)
  64. {
  65. struct ath10k *ar = htt->ar;
  66. int ret;
  67. lockdep_assert_held(&htt->tx_lock);
  68. ret = idr_alloc(&htt->pending_tx, skb, 0,
  69. htt->max_num_pending_tx, GFP_ATOMIC);
  70. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx alloc msdu_id %d\n", ret);
  71. return ret;
  72. }
  73. void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
  74. {
  75. struct ath10k *ar = htt->ar;
  76. lockdep_assert_held(&htt->tx_lock);
  77. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx free msdu_id %hu\n", msdu_id);
  78. idr_remove(&htt->pending_tx, msdu_id);
  79. }
  80. int ath10k_htt_tx_alloc(struct ath10k_htt *htt)
  81. {
  82. struct ath10k *ar = htt->ar;
  83. int ret, size;
  84. ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
  85. htt->max_num_pending_tx);
  86. spin_lock_init(&htt->tx_lock);
  87. idr_init(&htt->pending_tx);
  88. size = htt->max_num_pending_tx * sizeof(struct ath10k_htt_txbuf);
  89. htt->txbuf.vaddr = dma_alloc_coherent(ar->dev, size,
  90. &htt->txbuf.paddr,
  91. GFP_DMA);
  92. if (!htt->txbuf.vaddr) {
  93. ath10k_err(ar, "failed to alloc tx buffer\n");
  94. ret = -ENOMEM;
  95. goto free_idr_pending_tx;
  96. }
  97. if (!ar->hw_params.continuous_frag_desc)
  98. goto skip_frag_desc_alloc;
  99. size = htt->max_num_pending_tx * sizeof(struct htt_msdu_ext_desc);
  100. htt->frag_desc.vaddr = dma_alloc_coherent(ar->dev, size,
  101. &htt->frag_desc.paddr,
  102. GFP_DMA);
  103. if (!htt->frag_desc.vaddr) {
  104. ath10k_warn(ar, "failed to alloc fragment desc memory\n");
  105. ret = -ENOMEM;
  106. goto free_txbuf;
  107. }
  108. skip_frag_desc_alloc:
  109. return 0;
  110. free_txbuf:
  111. size = htt->max_num_pending_tx *
  112. sizeof(struct ath10k_htt_txbuf);
  113. dma_free_coherent(htt->ar->dev, size, htt->txbuf.vaddr,
  114. htt->txbuf.paddr);
  115. free_idr_pending_tx:
  116. idr_destroy(&htt->pending_tx);
  117. return ret;
  118. }
  119. static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx)
  120. {
  121. struct ath10k *ar = ctx;
  122. struct ath10k_htt *htt = &ar->htt;
  123. struct htt_tx_done tx_done = {0};
  124. ath10k_dbg(ar, ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n", msdu_id);
  125. tx_done.discard = 1;
  126. tx_done.msdu_id = msdu_id;
  127. ath10k_txrx_tx_unref(htt, &tx_done);
  128. return 0;
  129. }
  130. void ath10k_htt_tx_free(struct ath10k_htt *htt)
  131. {
  132. int size;
  133. idr_for_each(&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar);
  134. idr_destroy(&htt->pending_tx);
  135. if (htt->txbuf.vaddr) {
  136. size = htt->max_num_pending_tx *
  137. sizeof(struct ath10k_htt_txbuf);
  138. dma_free_coherent(htt->ar->dev, size, htt->txbuf.vaddr,
  139. htt->txbuf.paddr);
  140. }
  141. if (htt->frag_desc.vaddr) {
  142. size = htt->max_num_pending_tx *
  143. sizeof(struct htt_msdu_ext_desc);
  144. dma_free_coherent(htt->ar->dev, size, htt->frag_desc.vaddr,
  145. htt->frag_desc.paddr);
  146. }
  147. }
  148. void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
  149. {
  150. dev_kfree_skb_any(skb);
  151. }
  152. void ath10k_htt_hif_tx_complete(struct ath10k *ar, struct sk_buff *skb)
  153. {
  154. dev_kfree_skb_any(skb);
  155. }
  156. EXPORT_SYMBOL(ath10k_htt_hif_tx_complete);
  157. int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
  158. {
  159. struct ath10k *ar = htt->ar;
  160. struct sk_buff *skb;
  161. struct htt_cmd *cmd;
  162. int len = 0;
  163. int ret;
  164. len += sizeof(cmd->hdr);
  165. len += sizeof(cmd->ver_req);
  166. skb = ath10k_htc_alloc_skb(ar, len);
  167. if (!skb)
  168. return -ENOMEM;
  169. skb_put(skb, len);
  170. cmd = (struct htt_cmd *)skb->data;
  171. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;
  172. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  173. if (ret) {
  174. dev_kfree_skb_any(skb);
  175. return ret;
  176. }
  177. return 0;
  178. }
  179. int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u8 mask, u64 cookie)
  180. {
  181. struct ath10k *ar = htt->ar;
  182. struct htt_stats_req *req;
  183. struct sk_buff *skb;
  184. struct htt_cmd *cmd;
  185. int len = 0, ret;
  186. len += sizeof(cmd->hdr);
  187. len += sizeof(cmd->stats_req);
  188. skb = ath10k_htc_alloc_skb(ar, len);
  189. if (!skb)
  190. return -ENOMEM;
  191. skb_put(skb, len);
  192. cmd = (struct htt_cmd *)skb->data;
  193. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;
  194. req = &cmd->stats_req;
  195. memset(req, 0, sizeof(*req));
  196. /* currently we support only max 8 bit masks so no need to worry
  197. * about endian support */
  198. req->upload_types[0] = mask;
  199. req->reset_types[0] = mask;
  200. req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
  201. req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
  202. req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);
  203. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  204. if (ret) {
  205. ath10k_warn(ar, "failed to send htt type stats request: %d",
  206. ret);
  207. dev_kfree_skb_any(skb);
  208. return ret;
  209. }
  210. return 0;
  211. }
  212. int ath10k_htt_send_frag_desc_bank_cfg(struct ath10k_htt *htt)
  213. {
  214. struct ath10k *ar = htt->ar;
  215. struct sk_buff *skb;
  216. struct htt_cmd *cmd;
  217. int ret, size;
  218. if (!ar->hw_params.continuous_frag_desc)
  219. return 0;
  220. if (!htt->frag_desc.paddr) {
  221. ath10k_warn(ar, "invalid frag desc memory\n");
  222. return -EINVAL;
  223. }
  224. size = sizeof(cmd->hdr) + sizeof(cmd->frag_desc_bank_cfg);
  225. skb = ath10k_htc_alloc_skb(ar, size);
  226. if (!skb)
  227. return -ENOMEM;
  228. skb_put(skb, size);
  229. cmd = (struct htt_cmd *)skb->data;
  230. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG;
  231. cmd->frag_desc_bank_cfg.info = 0;
  232. cmd->frag_desc_bank_cfg.num_banks = 1;
  233. cmd->frag_desc_bank_cfg.desc_size = sizeof(struct htt_msdu_ext_desc);
  234. cmd->frag_desc_bank_cfg.bank_base_addrs[0] =
  235. __cpu_to_le32(htt->frag_desc.paddr);
  236. cmd->frag_desc_bank_cfg.bank_id[0].bank_min_id = 0;
  237. cmd->frag_desc_bank_cfg.bank_id[0].bank_max_id =
  238. __cpu_to_le16(htt->max_num_pending_tx - 1);
  239. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  240. if (ret) {
  241. ath10k_warn(ar, "failed to send frag desc bank cfg request: %d\n",
  242. ret);
  243. dev_kfree_skb_any(skb);
  244. return ret;
  245. }
  246. return 0;
  247. }
  248. int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt)
  249. {
  250. struct ath10k *ar = htt->ar;
  251. struct sk_buff *skb;
  252. struct htt_cmd *cmd;
  253. struct htt_rx_ring_setup_ring *ring;
  254. const int num_rx_ring = 1;
  255. u16 flags;
  256. u32 fw_idx;
  257. int len;
  258. int ret;
  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. len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup.hdr)
  266. + (sizeof(*ring) * num_rx_ring);
  267. skb = ath10k_htc_alloc_skb(ar, len);
  268. if (!skb)
  269. return -ENOMEM;
  270. skb_put(skb, len);
  271. cmd = (struct htt_cmd *)skb->data;
  272. ring = &cmd->rx_setup.rings[0];
  273. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
  274. cmd->rx_setup.hdr.num_rings = 1;
  275. /* FIXME: do we need all of this? */
  276. flags = 0;
  277. flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
  278. flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
  279. flags |= HTT_RX_RING_FLAGS_PPDU_START;
  280. flags |= HTT_RX_RING_FLAGS_PPDU_END;
  281. flags |= HTT_RX_RING_FLAGS_MPDU_START;
  282. flags |= HTT_RX_RING_FLAGS_MPDU_END;
  283. flags |= HTT_RX_RING_FLAGS_MSDU_START;
  284. flags |= HTT_RX_RING_FLAGS_MSDU_END;
  285. flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
  286. flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
  287. flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
  288. flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
  289. flags |= HTT_RX_RING_FLAGS_CTRL_RX;
  290. flags |= HTT_RX_RING_FLAGS_MGMT_RX;
  291. flags |= HTT_RX_RING_FLAGS_NULL_RX;
  292. flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;
  293. fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
  294. ring->fw_idx_shadow_reg_paddr =
  295. __cpu_to_le32(htt->rx_ring.alloc_idx.paddr);
  296. ring->rx_ring_base_paddr = __cpu_to_le32(htt->rx_ring.base_paddr);
  297. ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
  298. ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
  299. ring->flags = __cpu_to_le16(flags);
  300. ring->fw_idx_init_val = __cpu_to_le16(fw_idx);
  301. #define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
  302. ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
  303. ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
  304. ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
  305. ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
  306. ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
  307. ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
  308. ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
  309. ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
  310. ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
  311. ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
  312. #undef desc_offset
  313. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  314. if (ret) {
  315. dev_kfree_skb_any(skb);
  316. return ret;
  317. }
  318. return 0;
  319. }
  320. int ath10k_htt_h2t_aggr_cfg_msg(struct ath10k_htt *htt,
  321. u8 max_subfrms_ampdu,
  322. u8 max_subfrms_amsdu)
  323. {
  324. struct ath10k *ar = htt->ar;
  325. struct htt_aggr_conf *aggr_conf;
  326. struct sk_buff *skb;
  327. struct htt_cmd *cmd;
  328. int len;
  329. int ret;
  330. /* Firmware defaults are: amsdu = 3 and ampdu = 64 */
  331. if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
  332. return -EINVAL;
  333. if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
  334. return -EINVAL;
  335. len = sizeof(cmd->hdr);
  336. len += sizeof(cmd->aggr_conf);
  337. skb = ath10k_htc_alloc_skb(ar, len);
  338. if (!skb)
  339. return -ENOMEM;
  340. skb_put(skb, len);
  341. cmd = (struct htt_cmd *)skb->data;
  342. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;
  343. aggr_conf = &cmd->aggr_conf;
  344. aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
  345. aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;
  346. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
  347. aggr_conf->max_num_amsdu_subframes,
  348. aggr_conf->max_num_ampdu_subframes);
  349. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  350. if (ret) {
  351. dev_kfree_skb_any(skb);
  352. return ret;
  353. }
  354. return 0;
  355. }
  356. int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
  357. {
  358. struct ath10k *ar = htt->ar;
  359. struct device *dev = ar->dev;
  360. struct sk_buff *txdesc = NULL;
  361. struct htt_cmd *cmd;
  362. struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
  363. u8 vdev_id = skb_cb->vdev_id;
  364. int len = 0;
  365. int msdu_id = -1;
  366. int res;
  367. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
  368. bool limit_mgmt_desc = false;
  369. bool is_probe_resp = false;
  370. if (ar->hw_params.max_probe_resp_desc_thres) {
  371. limit_mgmt_desc = true;
  372. if (ieee80211_is_probe_resp(hdr->frame_control))
  373. is_probe_resp = true;
  374. }
  375. res = ath10k_htt_tx_inc_pending(htt, limit_mgmt_desc, is_probe_resp);
  376. if (res)
  377. goto err;
  378. len += sizeof(cmd->hdr);
  379. len += sizeof(cmd->mgmt_tx);
  380. spin_lock_bh(&htt->tx_lock);
  381. res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
  382. spin_unlock_bh(&htt->tx_lock);
  383. if (res < 0)
  384. goto err_tx_dec;
  385. msdu_id = res;
  386. txdesc = ath10k_htc_alloc_skb(ar, len);
  387. if (!txdesc) {
  388. res = -ENOMEM;
  389. goto err_free_msdu_id;
  390. }
  391. skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
  392. DMA_TO_DEVICE);
  393. res = dma_mapping_error(dev, skb_cb->paddr);
  394. if (res) {
  395. res = -EIO;
  396. goto err_free_txdesc;
  397. }
  398. skb_put(txdesc, len);
  399. cmd = (struct htt_cmd *)txdesc->data;
  400. memset(cmd, 0, len);
  401. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_MGMT_TX;
  402. cmd->mgmt_tx.msdu_paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
  403. cmd->mgmt_tx.len = __cpu_to_le32(msdu->len);
  404. cmd->mgmt_tx.desc_id = __cpu_to_le32(msdu_id);
  405. cmd->mgmt_tx.vdev_id = __cpu_to_le32(vdev_id);
  406. memcpy(cmd->mgmt_tx.hdr, msdu->data,
  407. min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
  408. skb_cb->htt.txbuf = NULL;
  409. res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
  410. if (res)
  411. goto err_unmap_msdu;
  412. return 0;
  413. err_unmap_msdu:
  414. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  415. err_free_txdesc:
  416. dev_kfree_skb_any(txdesc);
  417. err_free_msdu_id:
  418. spin_lock_bh(&htt->tx_lock);
  419. ath10k_htt_tx_free_msdu_id(htt, msdu_id);
  420. spin_unlock_bh(&htt->tx_lock);
  421. err_tx_dec:
  422. ath10k_htt_tx_dec_pending(htt, limit_mgmt_desc);
  423. err:
  424. return res;
  425. }
  426. int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
  427. {
  428. struct ath10k *ar = htt->ar;
  429. struct device *dev = ar->dev;
  430. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
  431. struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
  432. struct ath10k_hif_sg_item sg_items[2];
  433. struct htt_data_tx_desc_frag *frags;
  434. u8 vdev_id = skb_cb->vdev_id;
  435. u8 tid = skb_cb->htt.tid;
  436. int prefetch_len;
  437. int res;
  438. u8 flags0 = 0;
  439. u16 msdu_id, flags1 = 0;
  440. u32 frags_paddr = 0;
  441. struct htt_msdu_ext_desc *ext_desc = NULL;
  442. bool limit_mgmt_desc = false;
  443. bool is_probe_resp = false;
  444. if (unlikely(ieee80211_is_mgmt(hdr->frame_control)) &&
  445. ar->hw_params.max_probe_resp_desc_thres) {
  446. limit_mgmt_desc = true;
  447. if (ieee80211_is_probe_resp(hdr->frame_control))
  448. is_probe_resp = true;
  449. }
  450. res = ath10k_htt_tx_inc_pending(htt, limit_mgmt_desc, is_probe_resp);
  451. if (res)
  452. goto err;
  453. spin_lock_bh(&htt->tx_lock);
  454. res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
  455. spin_unlock_bh(&htt->tx_lock);
  456. if (res < 0)
  457. goto err_tx_dec;
  458. msdu_id = res;
  459. prefetch_len = min(htt->prefetch_len, msdu->len);
  460. prefetch_len = roundup(prefetch_len, 4);
  461. skb_cb->htt.txbuf = &htt->txbuf.vaddr[msdu_id];
  462. skb_cb->htt.txbuf_paddr = htt->txbuf.paddr +
  463. (sizeof(struct ath10k_htt_txbuf) * msdu_id);
  464. if ((ieee80211_is_action(hdr->frame_control) ||
  465. ieee80211_is_deauth(hdr->frame_control) ||
  466. ieee80211_is_disassoc(hdr->frame_control)) &&
  467. ieee80211_has_protected(hdr->frame_control)) {
  468. skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
  469. } else if (!skb_cb->htt.nohwcrypt &&
  470. skb_cb->txmode == ATH10K_HW_TXRX_RAW &&
  471. ieee80211_has_protected(hdr->frame_control)) {
  472. skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
  473. }
  474. skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
  475. DMA_TO_DEVICE);
  476. res = dma_mapping_error(dev, skb_cb->paddr);
  477. if (res) {
  478. res = -EIO;
  479. goto err_free_msdu_id;
  480. }
  481. switch (skb_cb->txmode) {
  482. case ATH10K_HW_TXRX_RAW:
  483. case ATH10K_HW_TXRX_NATIVE_WIFI:
  484. flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
  485. /* pass through */
  486. case ATH10K_HW_TXRX_ETHERNET:
  487. if (ar->hw_params.continuous_frag_desc) {
  488. memset(&htt->frag_desc.vaddr[msdu_id], 0,
  489. sizeof(struct htt_msdu_ext_desc));
  490. frags = (struct htt_data_tx_desc_frag *)
  491. &htt->frag_desc.vaddr[msdu_id].frags;
  492. ext_desc = &htt->frag_desc.vaddr[msdu_id];
  493. frags[0].tword_addr.paddr_lo =
  494. __cpu_to_le32(skb_cb->paddr);
  495. frags[0].tword_addr.paddr_hi = 0;
  496. frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);
  497. frags_paddr = htt->frag_desc.paddr +
  498. (sizeof(struct htt_msdu_ext_desc) * msdu_id);
  499. } else {
  500. frags = skb_cb->htt.txbuf->frags;
  501. frags[0].dword_addr.paddr =
  502. __cpu_to_le32(skb_cb->paddr);
  503. frags[0].dword_addr.len = __cpu_to_le32(msdu->len);
  504. frags[1].dword_addr.paddr = 0;
  505. frags[1].dword_addr.len = 0;
  506. frags_paddr = skb_cb->htt.txbuf_paddr;
  507. }
  508. flags0 |= SM(skb_cb->txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
  509. break;
  510. case ATH10K_HW_TXRX_MGMT:
  511. flags0 |= SM(ATH10K_HW_TXRX_MGMT,
  512. HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
  513. flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
  514. frags_paddr = skb_cb->paddr;
  515. break;
  516. }
  517. /* Normally all commands go through HTC which manages tx credits for
  518. * each endpoint and notifies when tx is completed.
  519. *
  520. * HTT endpoint is creditless so there's no need to care about HTC
  521. * flags. In that case it is trivial to fill the HTC header here.
  522. *
  523. * MSDU transmission is considered completed upon HTT event. This
  524. * implies no relevant resources can be freed until after the event is
  525. * received. That's why HTC tx completion handler itself is ignored by
  526. * setting NULL to transfer_context for all sg items.
  527. *
  528. * There is simply no point in pushing HTT TX_FRM through HTC tx path
  529. * as it's a waste of resources. By bypassing HTC it is possible to
  530. * avoid extra memory allocations, compress data structures and thus
  531. * improve performance. */
  532. skb_cb->htt.txbuf->htc_hdr.eid = htt->eid;
  533. skb_cb->htt.txbuf->htc_hdr.len = __cpu_to_le16(
  534. sizeof(skb_cb->htt.txbuf->cmd_hdr) +
  535. sizeof(skb_cb->htt.txbuf->cmd_tx) +
  536. prefetch_len);
  537. skb_cb->htt.txbuf->htc_hdr.flags = 0;
  538. if (skb_cb->htt.nohwcrypt)
  539. flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
  540. if (!skb_cb->is_protected)
  541. flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
  542. flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
  543. flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
  544. if (msdu->ip_summed == CHECKSUM_PARTIAL &&
  545. !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
  546. flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
  547. flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
  548. if (ar->hw_params.continuous_frag_desc)
  549. ext_desc->flags |= HTT_MSDU_CHECKSUM_ENABLE;
  550. }
  551. /* Prevent firmware from sending up tx inspection requests. There's
  552. * nothing ath10k can do with frames requested for inspection so force
  553. * it to simply rely a regular tx completion with discard status.
  554. */
  555. flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
  556. skb_cb->htt.txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
  557. skb_cb->htt.txbuf->cmd_tx.flags0 = flags0;
  558. skb_cb->htt.txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
  559. skb_cb->htt.txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
  560. skb_cb->htt.txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
  561. skb_cb->htt.txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
  562. skb_cb->htt.txbuf->cmd_tx.peerid = __cpu_to_le16(HTT_INVALID_PEERID);
  563. skb_cb->htt.txbuf->cmd_tx.freq = __cpu_to_le16(skb_cb->htt.freq);
  564. trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
  565. ath10k_dbg(ar, ATH10K_DBG_HTT,
  566. "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %08x, msdu_paddr %08x vdev %hhu tid %hhu freq %hu\n",
  567. flags0, flags1, msdu->len, msdu_id, frags_paddr,
  568. (u32)skb_cb->paddr, vdev_id, tid, skb_cb->htt.freq);
  569. ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
  570. msdu->data, msdu->len);
  571. trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
  572. trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
  573. sg_items[0].transfer_id = 0;
  574. sg_items[0].transfer_context = NULL;
  575. sg_items[0].vaddr = &skb_cb->htt.txbuf->htc_hdr;
  576. sg_items[0].paddr = skb_cb->htt.txbuf_paddr +
  577. sizeof(skb_cb->htt.txbuf->frags);
  578. sg_items[0].len = sizeof(skb_cb->htt.txbuf->htc_hdr) +
  579. sizeof(skb_cb->htt.txbuf->cmd_hdr) +
  580. sizeof(skb_cb->htt.txbuf->cmd_tx);
  581. sg_items[1].transfer_id = 0;
  582. sg_items[1].transfer_context = NULL;
  583. sg_items[1].vaddr = msdu->data;
  584. sg_items[1].paddr = skb_cb->paddr;
  585. sg_items[1].len = prefetch_len;
  586. res = ath10k_hif_tx_sg(htt->ar,
  587. htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
  588. sg_items, ARRAY_SIZE(sg_items));
  589. if (res)
  590. goto err_unmap_msdu;
  591. return 0;
  592. err_unmap_msdu:
  593. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  594. err_free_msdu_id:
  595. spin_lock_bh(&htt->tx_lock);
  596. ath10k_htt_tx_free_msdu_id(htt, msdu_id);
  597. spin_unlock_bh(&htt->tx_lock);
  598. err_tx_dec:
  599. ath10k_htt_tx_dec_pending(htt, limit_mgmt_desc);
  600. err:
  601. return res;
  602. }