txrx.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. if (tx_done->discard) {
  68. ieee80211_free_txskb(htt->ar->hw, msdu);
  69. goto exit;
  70. }
  71. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  72. info->flags |= IEEE80211_TX_STAT_ACK;
  73. if (tx_done->no_ack)
  74. info->flags &= ~IEEE80211_TX_STAT_ACK;
  75. ieee80211_tx_status(htt->ar->hw, msdu);
  76. /* we do not own the msdu anymore */
  77. exit:
  78. htt->pending_tx[tx_done->msdu_id] = NULL;
  79. ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
  80. __ath10k_htt_tx_dec_pending(htt);
  81. if (htt->num_pending_tx == 0)
  82. wake_up(&htt->empty_tx_wq);
  83. }
  84. struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
  85. const u8 *addr)
  86. {
  87. struct ath10k_peer *peer;
  88. lockdep_assert_held(&ar->data_lock);
  89. list_for_each_entry(peer, &ar->peers, list) {
  90. if (peer->vdev_id != vdev_id)
  91. continue;
  92. if (memcmp(peer->addr, addr, ETH_ALEN))
  93. continue;
  94. return peer;
  95. }
  96. return NULL;
  97. }
  98. struct ath10k_peer *ath10k_peer_find_by_id(struct ath10k *ar, int peer_id)
  99. {
  100. struct ath10k_peer *peer;
  101. lockdep_assert_held(&ar->data_lock);
  102. list_for_each_entry(peer, &ar->peers, list)
  103. if (test_bit(peer_id, peer->peer_ids))
  104. return peer;
  105. return NULL;
  106. }
  107. static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
  108. const u8 *addr, bool expect_mapped)
  109. {
  110. int ret;
  111. ret = wait_event_timeout(ar->peer_mapping_wq, ({
  112. bool mapped;
  113. spin_lock_bh(&ar->data_lock);
  114. mapped = !!ath10k_peer_find(ar, vdev_id, addr);
  115. spin_unlock_bh(&ar->data_lock);
  116. mapped == expect_mapped;
  117. }), 3*HZ);
  118. if (ret <= 0)
  119. return -ETIMEDOUT;
  120. return 0;
  121. }
  122. int ath10k_wait_for_peer_created(struct ath10k *ar, int vdev_id, const u8 *addr)
  123. {
  124. return ath10k_wait_for_peer_common(ar, vdev_id, addr, true);
  125. }
  126. int ath10k_wait_for_peer_deleted(struct ath10k *ar, int vdev_id, const u8 *addr)
  127. {
  128. return ath10k_wait_for_peer_common(ar, vdev_id, addr, false);
  129. }
  130. void ath10k_peer_map_event(struct ath10k_htt *htt,
  131. struct htt_peer_map_event *ev)
  132. {
  133. struct ath10k *ar = htt->ar;
  134. struct ath10k_peer *peer;
  135. spin_lock_bh(&ar->data_lock);
  136. peer = ath10k_peer_find(ar, ev->vdev_id, ev->addr);
  137. if (!peer) {
  138. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  139. if (!peer)
  140. goto exit;
  141. peer->vdev_id = ev->vdev_id;
  142. ether_addr_copy(peer->addr, ev->addr);
  143. list_add(&peer->list, &ar->peers);
  144. wake_up(&ar->peer_mapping_wq);
  145. }
  146. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer map vdev %d peer %pM id %d\n",
  147. ev->vdev_id, ev->addr, ev->peer_id);
  148. set_bit(ev->peer_id, peer->peer_ids);
  149. exit:
  150. spin_unlock_bh(&ar->data_lock);
  151. }
  152. void ath10k_peer_unmap_event(struct ath10k_htt *htt,
  153. struct htt_peer_unmap_event *ev)
  154. {
  155. struct ath10k *ar = htt->ar;
  156. struct ath10k_peer *peer;
  157. spin_lock_bh(&ar->data_lock);
  158. peer = ath10k_peer_find_by_id(ar, ev->peer_id);
  159. if (!peer) {
  160. ath10k_warn(ar, "peer-unmap-event: unknown peer id %d\n",
  161. ev->peer_id);
  162. goto exit;
  163. }
  164. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer unmap vdev %d peer %pM id %d\n",
  165. peer->vdev_id, peer->addr, ev->peer_id);
  166. clear_bit(ev->peer_id, peer->peer_ids);
  167. if (bitmap_empty(peer->peer_ids, ATH10K_MAX_NUM_PEER_IDS)) {
  168. list_del(&peer->list);
  169. kfree(peer);
  170. wake_up(&ar->peer_mapping_wq);
  171. }
  172. exit:
  173. spin_unlock_bh(&ar->data_lock);
  174. }