txrx.c 6.2 KB

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