txrx.c 6.7 KB

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