txrx.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2016 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 "core.h"
  18. #include "txrx.h"
  19. #include "htt.h"
  20. #include "mac.h"
  21. #include "debug.h"
  22. static void ath10k_report_offchan_tx(struct ath10k *ar, struct sk_buff *skb)
  23. {
  24. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  25. if (likely(!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)))
  26. return;
  27. if (ath10k_mac_tx_frm_has_freq(ar))
  28. return;
  29. /* If the original wait_for_completion() timed out before
  30. * {data,mgmt}_tx_completed() was called then we could complete
  31. * offchan_tx_completed for a different skb. Prevent this by using
  32. * offchan_tx_skb.
  33. */
  34. spin_lock_bh(&ar->data_lock);
  35. if (ar->offchan_tx_skb != skb) {
  36. ath10k_warn(ar, "completed old offchannel frame\n");
  37. goto out;
  38. }
  39. complete(&ar->offchan_tx_completed);
  40. ar->offchan_tx_skb = NULL; /* just for sanity */
  41. ath10k_dbg(ar, ATH10K_DBG_HTT, "completed offchannel skb %pK\n", skb);
  42. out:
  43. spin_unlock_bh(&ar->data_lock);
  44. }
  45. int ath10k_txrx_tx_unref(struct ath10k_htt *htt,
  46. const struct htt_tx_done *tx_done)
  47. {
  48. struct ath10k *ar = htt->ar;
  49. struct device *dev = ar->dev;
  50. struct ieee80211_tx_info *info;
  51. struct ieee80211_txq *txq;
  52. struct ath10k_skb_cb *skb_cb;
  53. struct ath10k_txq *artxq;
  54. struct sk_buff *msdu;
  55. ath10k_dbg(ar, ATH10K_DBG_HTT,
  56. "htt tx completion msdu_id %u status %d\n",
  57. tx_done->msdu_id, tx_done->status);
  58. if (tx_done->msdu_id >= htt->max_num_pending_tx) {
  59. ath10k_warn(ar, "warning: msdu_id %d too big, ignoring\n",
  60. tx_done->msdu_id);
  61. return -EINVAL;
  62. }
  63. spin_lock_bh(&htt->tx_lock);
  64. msdu = idr_find(&htt->pending_tx, tx_done->msdu_id);
  65. if (!msdu) {
  66. ath10k_warn(ar, "received tx completion for invalid msdu_id: %d\n",
  67. tx_done->msdu_id);
  68. spin_unlock_bh(&htt->tx_lock);
  69. return -ENOENT;
  70. }
  71. skb_cb = ATH10K_SKB_CB(msdu);
  72. txq = skb_cb->txq;
  73. if (txq) {
  74. artxq = (void *)txq->drv_priv;
  75. artxq->num_fw_queued--;
  76. }
  77. ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
  78. ath10k_htt_tx_dec_pending(htt);
  79. if (htt->num_pending_tx == 0)
  80. wake_up(&htt->empty_tx_wq);
  81. spin_unlock_bh(&htt->tx_lock);
  82. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  83. ath10k_report_offchan_tx(htt->ar, msdu);
  84. info = IEEE80211_SKB_CB(msdu);
  85. memset(&info->status, 0, sizeof(info->status));
  86. trace_ath10k_txrx_tx_unref(ar, tx_done->msdu_id);
  87. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  88. info->flags |= IEEE80211_TX_STAT_ACK;
  89. if (tx_done->status == HTT_TX_COMPL_STATE_NOACK)
  90. info->flags &= ~IEEE80211_TX_STAT_ACK;
  91. if ((tx_done->status == HTT_TX_COMPL_STATE_ACK) &&
  92. (info->flags & IEEE80211_TX_CTL_NO_ACK))
  93. info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  94. if (tx_done->status == HTT_TX_COMPL_STATE_DISCARD) {
  95. if (info->flags & IEEE80211_TX_CTL_NO_ACK)
  96. info->flags &= ~IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  97. else
  98. info->flags &= ~IEEE80211_TX_STAT_ACK;
  99. }
  100. ieee80211_tx_status(htt->ar->hw, msdu);
  101. /* we do not own the msdu anymore */
  102. return 0;
  103. }
  104. struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
  105. const u8 *addr)
  106. {
  107. struct ath10k_peer *peer;
  108. lockdep_assert_held(&ar->data_lock);
  109. list_for_each_entry(peer, &ar->peers, list) {
  110. if (peer->vdev_id != vdev_id)
  111. continue;
  112. if (!ether_addr_equal(peer->addr, addr))
  113. continue;
  114. return peer;
  115. }
  116. return NULL;
  117. }
  118. struct ath10k_peer *ath10k_peer_find_by_id(struct ath10k *ar, int peer_id)
  119. {
  120. struct ath10k_peer *peer;
  121. lockdep_assert_held(&ar->data_lock);
  122. list_for_each_entry(peer, &ar->peers, list)
  123. if (test_bit(peer_id, peer->peer_ids))
  124. return peer;
  125. return NULL;
  126. }
  127. static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
  128. const u8 *addr, bool expect_mapped)
  129. {
  130. long time_left;
  131. time_left = wait_event_timeout(ar->peer_mapping_wq, ({
  132. bool mapped;
  133. spin_lock_bh(&ar->data_lock);
  134. mapped = !!ath10k_peer_find(ar, vdev_id, addr);
  135. spin_unlock_bh(&ar->data_lock);
  136. (mapped == expect_mapped ||
  137. test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags));
  138. }), 3 * HZ);
  139. if (time_left == 0)
  140. return -ETIMEDOUT;
  141. return 0;
  142. }
  143. int ath10k_wait_for_peer_created(struct ath10k *ar, int vdev_id, const u8 *addr)
  144. {
  145. return ath10k_wait_for_peer_common(ar, vdev_id, addr, true);
  146. }
  147. int ath10k_wait_for_peer_deleted(struct ath10k *ar, int vdev_id, const u8 *addr)
  148. {
  149. return ath10k_wait_for_peer_common(ar, vdev_id, addr, false);
  150. }
  151. void ath10k_peer_map_event(struct ath10k_htt *htt,
  152. struct htt_peer_map_event *ev)
  153. {
  154. struct ath10k *ar = htt->ar;
  155. struct ath10k_peer *peer;
  156. if (ev->peer_id >= ATH10K_MAX_NUM_PEER_IDS) {
  157. ath10k_warn(ar,
  158. "received htt peer map event with idx out of bounds: %hu\n",
  159. ev->peer_id);
  160. return;
  161. }
  162. spin_lock_bh(&ar->data_lock);
  163. peer = ath10k_peer_find(ar, ev->vdev_id, ev->addr);
  164. if (!peer) {
  165. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  166. if (!peer)
  167. goto exit;
  168. peer->vdev_id = ev->vdev_id;
  169. ether_addr_copy(peer->addr, ev->addr);
  170. list_add(&peer->list, &ar->peers);
  171. wake_up(&ar->peer_mapping_wq);
  172. }
  173. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer map vdev %d peer %pM id %d\n",
  174. ev->vdev_id, ev->addr, ev->peer_id);
  175. WARN_ON(ar->peer_map[ev->peer_id] && (ar->peer_map[ev->peer_id] != peer));
  176. ar->peer_map[ev->peer_id] = peer;
  177. set_bit(ev->peer_id, peer->peer_ids);
  178. exit:
  179. spin_unlock_bh(&ar->data_lock);
  180. }
  181. void ath10k_peer_unmap_event(struct ath10k_htt *htt,
  182. struct htt_peer_unmap_event *ev)
  183. {
  184. struct ath10k *ar = htt->ar;
  185. struct ath10k_peer *peer;
  186. if (ev->peer_id >= ATH10K_MAX_NUM_PEER_IDS) {
  187. ath10k_warn(ar,
  188. "received htt peer unmap event with idx out of bounds: %hu\n",
  189. ev->peer_id);
  190. return;
  191. }
  192. spin_lock_bh(&ar->data_lock);
  193. peer = ath10k_peer_find_by_id(ar, ev->peer_id);
  194. if (!peer) {
  195. ath10k_warn(ar, "peer-unmap-event: unknown peer id %d\n",
  196. ev->peer_id);
  197. goto exit;
  198. }
  199. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer unmap vdev %d peer %pM id %d\n",
  200. peer->vdev_id, peer->addr, ev->peer_id);
  201. ar->peer_map[ev->peer_id] = NULL;
  202. clear_bit(ev->peer_id, peer->peer_ids);
  203. if (bitmap_empty(peer->peer_ids, ATH10K_MAX_NUM_PEER_IDS)) {
  204. list_del(&peer->list);
  205. kfree(peer);
  206. wake_up(&ar->peer_mapping_wq);
  207. }
  208. exit:
  209. spin_unlock_bh(&ar->data_lock);
  210. }