txrx.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2016 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "core.h"
  19. #include "txrx.h"
  20. #include "htt.h"
  21. #include "mac.h"
  22. #include "debug.h"
  23. static void ath10k_report_offchan_tx(struct ath10k *ar, struct sk_buff *skb)
  24. {
  25. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  26. if (likely(!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)))
  27. return;
  28. if (ath10k_mac_tx_frm_has_freq(ar))
  29. return;
  30. /* If the original wait_for_completion() timed out before
  31. * {data,mgmt}_tx_completed() was called then we could complete
  32. * offchan_tx_completed for a different skb. Prevent this by using
  33. * offchan_tx_skb.
  34. */
  35. spin_lock_bh(&ar->data_lock);
  36. if (ar->offchan_tx_skb != skb) {
  37. ath10k_warn(ar, "completed old offchannel frame\n");
  38. goto out;
  39. }
  40. complete(&ar->offchan_tx_completed);
  41. ar->offchan_tx_skb = NULL; /* just for sanity */
  42. ath10k_dbg(ar, ATH10K_DBG_HTT, "completed offchannel skb %pK\n", skb);
  43. out:
  44. spin_unlock_bh(&ar->data_lock);
  45. }
  46. int ath10k_txrx_tx_unref(struct ath10k_htt *htt,
  47. const struct htt_tx_done *tx_done)
  48. {
  49. struct ath10k *ar = htt->ar;
  50. struct device *dev = ar->dev;
  51. struct ieee80211_tx_info *info;
  52. struct ieee80211_txq *txq;
  53. struct ath10k_skb_cb *skb_cb;
  54. struct ath10k_txq *artxq;
  55. struct sk_buff *msdu;
  56. ath10k_dbg(ar, ATH10K_DBG_HTT,
  57. "htt tx completion msdu_id %u status %d\n",
  58. tx_done->msdu_id, tx_done->status);
  59. if (tx_done->msdu_id >= htt->max_num_pending_tx) {
  60. ath10k_warn(ar, "warning: msdu_id %d too big, ignoring\n",
  61. tx_done->msdu_id);
  62. return -EINVAL;
  63. }
  64. spin_lock_bh(&htt->tx_lock);
  65. msdu = idr_find(&htt->pending_tx, tx_done->msdu_id);
  66. if (!msdu) {
  67. ath10k_warn(ar, "received tx completion for invalid msdu_id: %d\n",
  68. tx_done->msdu_id);
  69. spin_unlock_bh(&htt->tx_lock);
  70. return -ENOENT;
  71. }
  72. skb_cb = ATH10K_SKB_CB(msdu);
  73. txq = skb_cb->txq;
  74. if (txq) {
  75. artxq = (void *)txq->drv_priv;
  76. artxq->num_fw_queued--;
  77. }
  78. ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
  79. ath10k_htt_tx_dec_pending(htt);
  80. if (htt->num_pending_tx == 0)
  81. wake_up(&htt->empty_tx_wq);
  82. spin_unlock_bh(&htt->tx_lock);
  83. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  84. ath10k_report_offchan_tx(htt->ar, msdu);
  85. info = IEEE80211_SKB_CB(msdu);
  86. memset(&info->status, 0, sizeof(info->status));
  87. trace_ath10k_txrx_tx_unref(ar, tx_done->msdu_id);
  88. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  89. info->flags |= IEEE80211_TX_STAT_ACK;
  90. if (tx_done->status == HTT_TX_COMPL_STATE_NOACK)
  91. info->flags &= ~IEEE80211_TX_STAT_ACK;
  92. if ((tx_done->status == HTT_TX_COMPL_STATE_ACK) &&
  93. (info->flags & IEEE80211_TX_CTL_NO_ACK))
  94. info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  95. if (tx_done->status == HTT_TX_COMPL_STATE_DISCARD) {
  96. if (info->flags & IEEE80211_TX_CTL_NO_ACK)
  97. info->flags &= ~IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  98. else
  99. info->flags &= ~IEEE80211_TX_STAT_ACK;
  100. }
  101. if (tx_done->status == HTT_TX_COMPL_STATE_ACK &&
  102. tx_done->ack_rssi != ATH10K_INVALID_RSSI) {
  103. info->status.ack_signal = ATH10K_DEFAULT_NOISE_FLOOR +
  104. tx_done->ack_rssi;
  105. info->status.is_valid_ack_signal = true;
  106. }
  107. ieee80211_tx_status(htt->ar->hw, msdu);
  108. /* we do not own the msdu anymore */
  109. return 0;
  110. }
  111. struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
  112. const u8 *addr)
  113. {
  114. struct ath10k_peer *peer;
  115. lockdep_assert_held(&ar->data_lock);
  116. list_for_each_entry(peer, &ar->peers, list) {
  117. if (peer->vdev_id != vdev_id)
  118. continue;
  119. if (!ether_addr_equal(peer->addr, addr))
  120. continue;
  121. return peer;
  122. }
  123. return NULL;
  124. }
  125. struct ath10k_peer *ath10k_peer_find_by_id(struct ath10k *ar, int peer_id)
  126. {
  127. struct ath10k_peer *peer;
  128. lockdep_assert_held(&ar->data_lock);
  129. list_for_each_entry(peer, &ar->peers, list)
  130. if (test_bit(peer_id, peer->peer_ids))
  131. return peer;
  132. return NULL;
  133. }
  134. static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
  135. const u8 *addr, bool expect_mapped)
  136. {
  137. long time_left;
  138. time_left = wait_event_timeout(ar->peer_mapping_wq, ({
  139. bool mapped;
  140. spin_lock_bh(&ar->data_lock);
  141. mapped = !!ath10k_peer_find(ar, vdev_id, addr);
  142. spin_unlock_bh(&ar->data_lock);
  143. (mapped == expect_mapped ||
  144. test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags));
  145. }), 3 * HZ);
  146. if (time_left == 0)
  147. return -ETIMEDOUT;
  148. return 0;
  149. }
  150. int ath10k_wait_for_peer_created(struct ath10k *ar, int vdev_id, const u8 *addr)
  151. {
  152. return ath10k_wait_for_peer_common(ar, vdev_id, addr, true);
  153. }
  154. int ath10k_wait_for_peer_deleted(struct ath10k *ar, int vdev_id, const u8 *addr)
  155. {
  156. return ath10k_wait_for_peer_common(ar, vdev_id, addr, false);
  157. }
  158. void ath10k_peer_map_event(struct ath10k_htt *htt,
  159. struct htt_peer_map_event *ev)
  160. {
  161. struct ath10k *ar = htt->ar;
  162. struct ath10k_peer *peer;
  163. if (ev->peer_id >= ATH10K_MAX_NUM_PEER_IDS) {
  164. ath10k_warn(ar,
  165. "received htt peer map event with idx out of bounds: %hu\n",
  166. ev->peer_id);
  167. return;
  168. }
  169. spin_lock_bh(&ar->data_lock);
  170. peer = ath10k_peer_find(ar, ev->vdev_id, ev->addr);
  171. if (!peer) {
  172. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  173. if (!peer)
  174. goto exit;
  175. peer->vdev_id = ev->vdev_id;
  176. ether_addr_copy(peer->addr, ev->addr);
  177. list_add(&peer->list, &ar->peers);
  178. wake_up(&ar->peer_mapping_wq);
  179. }
  180. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer map vdev %d peer %pM id %d\n",
  181. ev->vdev_id, ev->addr, ev->peer_id);
  182. WARN_ON(ar->peer_map[ev->peer_id] && (ar->peer_map[ev->peer_id] != peer));
  183. ar->peer_map[ev->peer_id] = peer;
  184. set_bit(ev->peer_id, peer->peer_ids);
  185. exit:
  186. spin_unlock_bh(&ar->data_lock);
  187. }
  188. void ath10k_peer_unmap_event(struct ath10k_htt *htt,
  189. struct htt_peer_unmap_event *ev)
  190. {
  191. struct ath10k *ar = htt->ar;
  192. struct ath10k_peer *peer;
  193. if (ev->peer_id >= ATH10K_MAX_NUM_PEER_IDS) {
  194. ath10k_warn(ar,
  195. "received htt peer unmap event with idx out of bounds: %hu\n",
  196. ev->peer_id);
  197. return;
  198. }
  199. spin_lock_bh(&ar->data_lock);
  200. peer = ath10k_peer_find_by_id(ar, ev->peer_id);
  201. if (!peer) {
  202. ath10k_warn(ar, "peer-unmap-event: unknown peer id %d\n",
  203. ev->peer_id);
  204. goto exit;
  205. }
  206. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer unmap vdev %d peer %pM id %d\n",
  207. peer->vdev_id, peer->addr, ev->peer_id);
  208. ar->peer_map[ev->peer_id] = NULL;
  209. clear_bit(ev->peer_id, peer->peer_ids);
  210. if (bitmap_empty(peer->peer_ids, ATH10K_MAX_NUM_PEER_IDS)) {
  211. list_del(&peer->list);
  212. kfree(peer);
  213. wake_up(&ar->peer_mapping_wq);
  214. }
  215. exit:
  216. spin_unlock_bh(&ar->data_lock);
  217. }