txrx.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2005-2011 Atheros Communications Inc.
  4. * Copyright (c) 2011-2016 Qualcomm Atheros, Inc.
  5. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  6. */
  7. #include "core.h"
  8. #include "txrx.h"
  9. #include "htt.h"
  10. #include "mac.h"
  11. #include "debug.h"
  12. static void ath10k_report_offchan_tx(struct ath10k *ar, struct sk_buff *skb)
  13. {
  14. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  15. if (likely(!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)))
  16. return;
  17. if (ath10k_mac_tx_frm_has_freq(ar))
  18. return;
  19. /* If the original wait_for_completion() timed out before
  20. * {data,mgmt}_tx_completed() was called then we could complete
  21. * offchan_tx_completed for a different skb. Prevent this by using
  22. * offchan_tx_skb.
  23. */
  24. spin_lock_bh(&ar->data_lock);
  25. if (ar->offchan_tx_skb != skb) {
  26. ath10k_warn(ar, "completed old offchannel frame\n");
  27. goto out;
  28. }
  29. complete(&ar->offchan_tx_completed);
  30. ar->offchan_tx_skb = NULL; /* just for sanity */
  31. ath10k_dbg(ar, ATH10K_DBG_HTT, "completed offchannel skb %pK\n", skb);
  32. out:
  33. spin_unlock_bh(&ar->data_lock);
  34. }
  35. int ath10k_txrx_tx_unref(struct ath10k_htt *htt,
  36. const struct htt_tx_done *tx_done)
  37. {
  38. struct ieee80211_tx_status status;
  39. struct ath10k *ar = htt->ar;
  40. struct device *dev = ar->dev;
  41. struct ieee80211_tx_info *info;
  42. struct ieee80211_txq *txq;
  43. struct ath10k_skb_cb *skb_cb;
  44. struct ath10k_txq *artxq;
  45. struct sk_buff *msdu;
  46. u8 flags;
  47. ath10k_dbg(ar, ATH10K_DBG_HTT,
  48. "htt tx completion msdu_id %u status %d\n",
  49. tx_done->msdu_id, tx_done->status);
  50. if (tx_done->msdu_id >= htt->max_num_pending_tx) {
  51. ath10k_warn(ar, "warning: msdu_id %d too big, ignoring\n",
  52. tx_done->msdu_id);
  53. return -EINVAL;
  54. }
  55. spin_lock_bh(&htt->tx_lock);
  56. msdu = idr_find(&htt->pending_tx, tx_done->msdu_id);
  57. if (!msdu) {
  58. ath10k_warn(ar, "received tx completion for invalid msdu_id: %d\n",
  59. tx_done->msdu_id);
  60. spin_unlock_bh(&htt->tx_lock);
  61. return -ENOENT;
  62. }
  63. skb_cb = ATH10K_SKB_CB(msdu);
  64. txq = skb_cb->txq;
  65. if (txq) {
  66. artxq = (void *)txq->drv_priv;
  67. artxq->num_fw_queued--;
  68. }
  69. flags = skb_cb->flags;
  70. ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
  71. ath10k_htt_tx_dec_pending(htt);
  72. spin_unlock_bh(&htt->tx_lock);
  73. rcu_read_lock();
  74. if (txq && txq->sta && skb_cb->airtime_est)
  75. ieee80211_sta_register_airtime(txq->sta, txq->tid,
  76. skb_cb->airtime_est, 0);
  77. rcu_read_unlock();
  78. if (ar->bus_param.dev_type != ATH10K_DEV_TYPE_HL)
  79. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  80. ath10k_report_offchan_tx(htt->ar, msdu);
  81. info = IEEE80211_SKB_CB(msdu);
  82. memset(&info->status, 0, sizeof(info->status));
  83. info->status.rates[0].idx = -1;
  84. trace_ath10k_txrx_tx_unref(ar, tx_done->msdu_id);
  85. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  86. !(flags & ATH10K_SKB_F_NOACK_TID))
  87. info->flags |= IEEE80211_TX_STAT_ACK;
  88. if (tx_done->status == HTT_TX_COMPL_STATE_NOACK)
  89. info->flags &= ~IEEE80211_TX_STAT_ACK;
  90. if ((tx_done->status == HTT_TX_COMPL_STATE_ACK) &&
  91. ((info->flags & IEEE80211_TX_CTL_NO_ACK) ||
  92. (flags & ATH10K_SKB_F_NOACK_TID)))
  93. info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  94. if (tx_done->status == HTT_TX_COMPL_STATE_DISCARD) {
  95. if ((info->flags & IEEE80211_TX_CTL_NO_ACK) ||
  96. (flags & ATH10K_SKB_F_NOACK_TID))
  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.flags |= IEEE80211_TX_STATUS_ACK_SIGNAL_VALID;
  106. }
  107. memset(&status, 0, sizeof(status));
  108. status.skb = msdu;
  109. status.info = info;
  110. rcu_read_lock();
  111. if (txq)
  112. status.sta = txq->sta;
  113. ieee80211_tx_status_ext(htt->ar->hw, &status);
  114. rcu_read_unlock();
  115. /* we do not own the msdu anymore */
  116. return 0;
  117. }
  118. struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
  119. const u8 *addr)
  120. {
  121. struct ath10k_peer *peer;
  122. lockdep_assert_held(&ar->data_lock);
  123. list_for_each_entry(peer, &ar->peers, list) {
  124. if (peer->vdev_id != vdev_id)
  125. continue;
  126. if (!ether_addr_equal(peer->addr, addr))
  127. continue;
  128. return peer;
  129. }
  130. return NULL;
  131. }
  132. struct ath10k_peer *ath10k_peer_find_by_id(struct ath10k *ar, int peer_id)
  133. {
  134. struct ath10k_peer *peer;
  135. if (peer_id >= BITS_PER_TYPE(peer->peer_ids))
  136. return NULL;
  137. lockdep_assert_held(&ar->data_lock);
  138. list_for_each_entry(peer, &ar->peers, list)
  139. if (test_bit(peer_id, peer->peer_ids))
  140. return peer;
  141. return NULL;
  142. }
  143. static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
  144. const u8 *addr, bool expect_mapped)
  145. {
  146. long time_left;
  147. time_left = wait_event_timeout(ar->peer_mapping_wq, ({
  148. bool mapped;
  149. spin_lock_bh(&ar->data_lock);
  150. mapped = !!ath10k_peer_find(ar, vdev_id, addr);
  151. spin_unlock_bh(&ar->data_lock);
  152. (mapped == expect_mapped ||
  153. test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags));
  154. }), 3 * HZ);
  155. if (time_left == 0)
  156. return -ETIMEDOUT;
  157. return 0;
  158. }
  159. int ath10k_wait_for_peer_created(struct ath10k *ar, int vdev_id, const u8 *addr)
  160. {
  161. return ath10k_wait_for_peer_common(ar, vdev_id, addr, true);
  162. }
  163. int ath10k_wait_for_peer_deleted(struct ath10k *ar, int vdev_id, const u8 *addr)
  164. {
  165. return ath10k_wait_for_peer_common(ar, vdev_id, addr, false);
  166. }
  167. void ath10k_peer_map_event(struct ath10k_htt *htt,
  168. struct htt_peer_map_event *ev)
  169. {
  170. struct ath10k *ar = htt->ar;
  171. struct ath10k_peer *peer;
  172. if (ev->peer_id >= ATH10K_MAX_NUM_PEER_IDS) {
  173. ath10k_warn(ar,
  174. "received htt peer map event with idx out of bounds: %u\n",
  175. ev->peer_id);
  176. return;
  177. }
  178. spin_lock_bh(&ar->data_lock);
  179. peer = ath10k_peer_find(ar, ev->vdev_id, ev->addr);
  180. if (!peer) {
  181. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  182. if (!peer)
  183. goto exit;
  184. peer->vdev_id = ev->vdev_id;
  185. ether_addr_copy(peer->addr, ev->addr);
  186. list_add(&peer->list, &ar->peers);
  187. wake_up(&ar->peer_mapping_wq);
  188. }
  189. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer map vdev %d peer %pM id %d\n",
  190. ev->vdev_id, ev->addr, ev->peer_id);
  191. WARN_ON(ar->peer_map[ev->peer_id] && (ar->peer_map[ev->peer_id] != peer));
  192. ar->peer_map[ev->peer_id] = peer;
  193. set_bit(ev->peer_id, peer->peer_ids);
  194. exit:
  195. spin_unlock_bh(&ar->data_lock);
  196. }
  197. void ath10k_peer_unmap_event(struct ath10k_htt *htt,
  198. struct htt_peer_unmap_event *ev)
  199. {
  200. struct ath10k *ar = htt->ar;
  201. struct ath10k_peer *peer;
  202. if (ev->peer_id >= ATH10K_MAX_NUM_PEER_IDS) {
  203. ath10k_warn(ar,
  204. "received htt peer unmap event with idx out of bounds: %u\n",
  205. ev->peer_id);
  206. return;
  207. }
  208. spin_lock_bh(&ar->data_lock);
  209. peer = ath10k_peer_find_by_id(ar, ev->peer_id);
  210. if (!peer) {
  211. ath10k_warn(ar, "peer-unmap-event: unknown peer id %d\n",
  212. ev->peer_id);
  213. goto exit;
  214. }
  215. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt peer unmap vdev %d peer %pM id %d\n",
  216. peer->vdev_id, peer->addr, ev->peer_id);
  217. ar->peer_map[ev->peer_id] = NULL;
  218. clear_bit(ev->peer_id, peer->peer_ids);
  219. if (bitmap_empty(peer->peer_ids, ATH10K_MAX_NUM_PEER_IDS)) {
  220. list_del(&peer->list);
  221. kfree(peer);
  222. wake_up(&ar->peer_mapping_wq);
  223. }
  224. exit:
  225. spin_unlock_bh(&ar->data_lock);
  226. }