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