txrx.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 "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. if (!ATH10K_SKB_CB(skb)->htt.is_offchan)
  25. return;
  26. /* If the original wait_for_completion() timed out before
  27. * {data,mgmt}_tx_completed() was called then we could complete
  28. * offchan_tx_completed for a different skb. Prevent this by using
  29. * offchan_tx_skb. */
  30. spin_lock_bh(&ar->data_lock);
  31. if (ar->offchan_tx_skb != skb) {
  32. ath10k_warn(ar, "completed old offchannel frame\n");
  33. goto out;
  34. }
  35. complete(&ar->offchan_tx_completed);
  36. ar->offchan_tx_skb = NULL; /* just for sanity */
  37. ath10k_dbg(ar, ATH10K_DBG_HTT, "completed offchannel skb %p\n", skb);
  38. out:
  39. spin_unlock_bh(&ar->data_lock);
  40. }
  41. void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
  42. const struct htt_tx_done *tx_done)
  43. {
  44. struct ath10k *ar = htt->ar;
  45. struct device *dev = ar->dev;
  46. struct ieee80211_tx_info *info;
  47. struct ath10k_skb_cb *skb_cb;
  48. struct sk_buff *msdu;
  49. lockdep_assert_held(&htt->tx_lock);
  50. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx completion msdu_id %u discard %d no_ack %d\n",
  51. tx_done->msdu_id, !!tx_done->discard, !!tx_done->no_ack);
  52. if (tx_done->msdu_id >= htt->max_num_pending_tx) {
  53. ath10k_warn(ar, "warning: msdu_id %d too big, ignoring\n",
  54. tx_done->msdu_id);
  55. return;
  56. }
  57. msdu = htt->pending_tx[tx_done->msdu_id];
  58. skb_cb = ATH10K_SKB_CB(msdu);
  59. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  60. if (skb_cb->htt.txbuf)
  61. dma_pool_free(htt->tx_pool,
  62. skb_cb->htt.txbuf,
  63. skb_cb->htt.txbuf_paddr);
  64. ath10k_report_offchan_tx(htt->ar, msdu);
  65. info = IEEE80211_SKB_CB(msdu);
  66. memset(&info->status, 0, sizeof(info->status));
  67. trace_ath10k_txrx_tx_unref(ar, tx_done->msdu_id);
  68. if (tx_done->discard) {
  69. ieee80211_free_txskb(htt->ar->hw, msdu);
  70. goto exit;
  71. }
  72. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  73. info->flags |= IEEE80211_TX_STAT_ACK;
  74. if (tx_done->no_ack)
  75. info->flags &= ~IEEE80211_TX_STAT_ACK;
  76. ieee80211_tx_status(htt->ar->hw, msdu);
  77. /* we do not own the msdu anymore */
  78. exit:
  79. htt->pending_tx[tx_done->msdu_id] = NULL;
  80. ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
  81. __ath10k_htt_tx_dec_pending(htt);
  82. if (htt->num_pending_tx == 0)
  83. wake_up(&htt->empty_tx_wq);
  84. }
  85. struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
  86. const u8 *addr)
  87. {
  88. struct ath10k_peer *peer;
  89. lockdep_assert_held(&ar->data_lock);
  90. list_for_each_entry(peer, &ar->peers, list) {
  91. if (peer->vdev_id != vdev_id)
  92. continue;
  93. if (memcmp(peer->addr, addr, ETH_ALEN))
  94. continue;
  95. return peer;
  96. }
  97. return NULL;
  98. }
  99. struct ath10k_peer *ath10k_peer_find_by_id(struct ath10k *ar, int peer_id)
  100. {
  101. struct ath10k_peer *peer;
  102. lockdep_assert_held(&ar->data_lock);
  103. list_for_each_entry(peer, &ar->peers, list)
  104. if (test_bit(peer_id, peer->peer_ids))
  105. return peer;
  106. return NULL;
  107. }
  108. static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
  109. const u8 *addr, bool expect_mapped)
  110. {
  111. int ret;
  112. ret = wait_event_timeout(ar->peer_mapping_wq, ({
  113. bool mapped;
  114. spin_lock_bh(&ar->data_lock);
  115. mapped = !!ath10k_peer_find(ar, vdev_id, addr);
  116. spin_unlock_bh(&ar->data_lock);
  117. (mapped == expect_mapped ||
  118. test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags));
  119. }), 3*HZ);
  120. if (ret <= 0)
  121. return -ETIMEDOUT;
  122. return 0;
  123. }
  124. int ath10k_wait_for_peer_created(struct ath10k *ar, int vdev_id, const u8 *addr)
  125. {
  126. return ath10k_wait_for_peer_common(ar, vdev_id, addr, true);
  127. }
  128. int ath10k_wait_for_peer_deleted(struct ath10k *ar, int vdev_id, const u8 *addr)
  129. {
  130. return ath10k_wait_for_peer_common(ar, vdev_id, addr, false);
  131. }
  132. void ath10k_peer_map_event(struct ath10k_htt *htt,
  133. struct htt_peer_map_event *ev)
  134. {
  135. struct ath10k *ar = htt->ar;
  136. struct ath10k_peer *peer;
  137. spin_lock_bh(&ar->data_lock);
  138. peer = ath10k_peer_find(ar, ev->vdev_id, ev->addr);
  139. if (!peer) {
  140. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  141. if (!peer)
  142. goto exit;
  143. peer->vdev_id = ev->vdev_id;
  144. ether_addr_copy(peer->addr, ev->addr);
  145. list_add(&peer->list, &ar->peers);
  146. wake_up(&ar->peer_mapping_wq);
  147. }
  148. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer map vdev %d peer %pM id %d\n",
  149. ev->vdev_id, ev->addr, ev->peer_id);
  150. set_bit(ev->peer_id, peer->peer_ids);
  151. exit:
  152. spin_unlock_bh(&ar->data_lock);
  153. }
  154. void ath10k_peer_unmap_event(struct ath10k_htt *htt,
  155. struct htt_peer_unmap_event *ev)
  156. {
  157. struct ath10k *ar = htt->ar;
  158. struct ath10k_peer *peer;
  159. spin_lock_bh(&ar->data_lock);
  160. peer = ath10k_peer_find_by_id(ar, ev->peer_id);
  161. if (!peer) {
  162. ath10k_warn(ar, "peer-unmap-event: unknown peer id %d\n",
  163. ev->peer_id);
  164. goto exit;
  165. }
  166. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer unmap vdev %d peer %pM id %d\n",
  167. peer->vdev_id, peer->addr, ev->peer_id);
  168. clear_bit(ev->peer_id, peer->peer_ids);
  169. if (bitmap_empty(peer->peer_ids, ATH10K_MAX_NUM_PEER_IDS)) {
  170. list_del(&peer->list);
  171. kfree(peer);
  172. wake_up(&ar->peer_mapping_wq);
  173. }
  174. exit:
  175. spin_unlock_bh(&ar->data_lock);
  176. }