txrx.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. ath10k_dbg(ar, ATH10K_DBG_HTT,
  50. "htt tx completion msdu_id %u discard %d no_ack %d success %d\n",
  51. tx_done->msdu_id, !!tx_done->discard,
  52. !!tx_done->no_ack, !!tx_done->success);
  53. if (tx_done->msdu_id >= htt->max_num_pending_tx) {
  54. ath10k_warn(ar, "warning: msdu_id %d too big, ignoring\n",
  55. tx_done->msdu_id);
  56. return;
  57. }
  58. spin_lock_bh(&htt->tx_lock);
  59. msdu = idr_find(&htt->pending_tx, tx_done->msdu_id);
  60. if (!msdu) {
  61. ath10k_warn(ar, "received tx completion for invalid msdu_id: %d\n",
  62. tx_done->msdu_id);
  63. spin_unlock_bh(&htt->tx_lock);
  64. return;
  65. }
  66. ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
  67. __ath10k_htt_tx_dec_pending(htt);
  68. if (htt->num_pending_tx == 0)
  69. wake_up(&htt->empty_tx_wq);
  70. spin_unlock_bh(&htt->tx_lock);
  71. skb_cb = ATH10K_SKB_CB(msdu);
  72. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  73. if (skb_cb->htt.txbuf)
  74. dma_pool_free(htt->tx_pool,
  75. skb_cb->htt.txbuf,
  76. skb_cb->htt.txbuf_paddr);
  77. ath10k_report_offchan_tx(htt->ar, msdu);
  78. info = IEEE80211_SKB_CB(msdu);
  79. memset(&info->status, 0, sizeof(info->status));
  80. trace_ath10k_txrx_tx_unref(ar, tx_done->msdu_id);
  81. if (tx_done->discard) {
  82. ieee80211_free_txskb(htt->ar->hw, msdu);
  83. return;
  84. }
  85. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  86. info->flags |= IEEE80211_TX_STAT_ACK;
  87. if (tx_done->no_ack)
  88. info->flags &= ~IEEE80211_TX_STAT_ACK;
  89. if (tx_done->success && (info->flags & IEEE80211_TX_CTL_NO_ACK))
  90. info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  91. ieee80211_tx_status(htt->ar->hw, msdu);
  92. /* we do not own the msdu anymore */
  93. }
  94. struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
  95. const u8 *addr)
  96. {
  97. struct ath10k_peer *peer;
  98. lockdep_assert_held(&ar->data_lock);
  99. list_for_each_entry(peer, &ar->peers, list) {
  100. if (peer->vdev_id != vdev_id)
  101. continue;
  102. if (memcmp(peer->addr, addr, ETH_ALEN))
  103. continue;
  104. return peer;
  105. }
  106. return NULL;
  107. }
  108. struct ath10k_peer *ath10k_peer_find_by_id(struct ath10k *ar, int peer_id)
  109. {
  110. struct ath10k_peer *peer;
  111. lockdep_assert_held(&ar->data_lock);
  112. list_for_each_entry(peer, &ar->peers, list)
  113. if (test_bit(peer_id, peer->peer_ids))
  114. return peer;
  115. return NULL;
  116. }
  117. static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
  118. const u8 *addr, bool expect_mapped)
  119. {
  120. long time_left;
  121. time_left = wait_event_timeout(ar->peer_mapping_wq, ({
  122. bool mapped;
  123. spin_lock_bh(&ar->data_lock);
  124. mapped = !!ath10k_peer_find(ar, vdev_id, addr);
  125. spin_unlock_bh(&ar->data_lock);
  126. (mapped == expect_mapped ||
  127. test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags));
  128. }), 3*HZ);
  129. if (time_left == 0)
  130. return -ETIMEDOUT;
  131. return 0;
  132. }
  133. int ath10k_wait_for_peer_created(struct ath10k *ar, int vdev_id, const u8 *addr)
  134. {
  135. return ath10k_wait_for_peer_common(ar, vdev_id, addr, true);
  136. }
  137. int ath10k_wait_for_peer_deleted(struct ath10k *ar, int vdev_id, const u8 *addr)
  138. {
  139. return ath10k_wait_for_peer_common(ar, vdev_id, addr, false);
  140. }
  141. void ath10k_peer_map_event(struct ath10k_htt *htt,
  142. struct htt_peer_map_event *ev)
  143. {
  144. struct ath10k *ar = htt->ar;
  145. struct ath10k_peer *peer;
  146. spin_lock_bh(&ar->data_lock);
  147. peer = ath10k_peer_find(ar, ev->vdev_id, ev->addr);
  148. if (!peer) {
  149. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  150. if (!peer)
  151. goto exit;
  152. peer->vdev_id = ev->vdev_id;
  153. ether_addr_copy(peer->addr, ev->addr);
  154. list_add(&peer->list, &ar->peers);
  155. wake_up(&ar->peer_mapping_wq);
  156. }
  157. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer map vdev %d peer %pM id %d\n",
  158. ev->vdev_id, ev->addr, ev->peer_id);
  159. set_bit(ev->peer_id, peer->peer_ids);
  160. exit:
  161. spin_unlock_bh(&ar->data_lock);
  162. }
  163. void ath10k_peer_unmap_event(struct ath10k_htt *htt,
  164. struct htt_peer_unmap_event *ev)
  165. {
  166. struct ath10k *ar = htt->ar;
  167. struct ath10k_peer *peer;
  168. spin_lock_bh(&ar->data_lock);
  169. peer = ath10k_peer_find_by_id(ar, ev->peer_id);
  170. if (!peer) {
  171. ath10k_warn(ar, "peer-unmap-event: unknown peer id %d\n",
  172. ev->peer_id);
  173. goto exit;
  174. }
  175. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer unmap vdev %d peer %pM id %d\n",
  176. peer->vdev_id, peer->addr, ev->peer_id);
  177. clear_bit(ev->peer_id, peer->peer_ids);
  178. if (bitmap_empty(peer->peer_ids, ATH10K_MAX_NUM_PEER_IDS)) {
  179. list_del(&peer->list);
  180. kfree(peer);
  181. wake_up(&ar->peer_mapping_wq);
  182. }
  183. exit:
  184. spin_unlock_bh(&ar->data_lock);
  185. }