1 // SPDX-License-Identifier: ISC
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.
14 static void ath10k_report_offchan_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
16 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
18 if (likely(!(info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
)))
21 if (ath10k_mac_tx_frm_has_freq(ar
))
24 /* If the original wait_for_completion() timed out before
25 * {data,mgmt}_tx_completed() was called then we could complete
26 * offchan_tx_completed for a different skb. Prevent this by using
29 spin_lock_bh(&ar
->data_lock
);
30 if (ar
->offchan_tx_skb
!= skb
) {
31 ath10k_warn(ar
, "completed old offchannel frame\n");
35 complete(&ar
->offchan_tx_completed
);
36 ar
->offchan_tx_skb
= NULL
; /* just for sanity */
38 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "completed offchannel skb %pK\n", skb
);
40 spin_unlock_bh(&ar
->data_lock
);
43 int ath10k_txrx_tx_unref(struct ath10k_htt
*htt
,
44 const struct htt_tx_done
*tx_done
)
46 struct ath10k
*ar
= htt
->ar
;
47 struct device
*dev
= ar
->dev
;
48 struct ieee80211_tx_info
*info
;
49 struct ieee80211_txq
*txq
;
50 struct ath10k_skb_cb
*skb_cb
;
51 struct ath10k_txq
*artxq
;
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
);
59 if (tx_done
->msdu_id
>= htt
->max_num_pending_tx
) {
60 ath10k_warn(ar
, "warning: msdu_id %d too big, ignoring\n",
65 spin_lock_bh(&htt
->tx_lock
);
66 msdu
= idr_find(&htt
->pending_tx
, tx_done
->msdu_id
);
68 ath10k_warn(ar
, "received tx completion for invalid msdu_id: %d\n",
70 spin_unlock_bh(&htt
->tx_lock
);
74 skb_cb
= ATH10K_SKB_CB(msdu
);
78 artxq
= (void *)txq
->drv_priv
;
79 artxq
->num_fw_queued
--;
82 flags
= skb_cb
->flags
;
83 ath10k_htt_tx_free_msdu_id(htt
, tx_done
->msdu_id
);
84 ath10k_htt_tx_dec_pending(htt
);
85 if (htt
->num_pending_tx
== 0)
86 wake_up(&htt
->empty_tx_wq
);
87 spin_unlock_bh(&htt
->tx_lock
);
90 if (txq
&& txq
->sta
&& skb_cb
->airtime_est
)
91 ieee80211_sta_register_airtime(txq
->sta
, txq
->tid
,
92 skb_cb
->airtime_est
, 0);
95 if (ar
->bus_param
.dev_type
!= ATH10K_DEV_TYPE_HL
)
96 dma_unmap_single(dev
, skb_cb
->paddr
, msdu
->len
, DMA_TO_DEVICE
);
98 ath10k_report_offchan_tx(htt
->ar
, msdu
);
100 info
= IEEE80211_SKB_CB(msdu
);
101 memset(&info
->status
, 0, sizeof(info
->status
));
102 info
->status
.rates
[0].idx
= -1;
104 trace_ath10k_txrx_tx_unref(ar
, tx_done
->msdu_id
);
106 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
) &&
107 !(flags
& ATH10K_SKB_F_NOACK_TID
))
108 info
->flags
|= IEEE80211_TX_STAT_ACK
;
110 if (tx_done
->status
== HTT_TX_COMPL_STATE_NOACK
)
111 info
->flags
&= ~IEEE80211_TX_STAT_ACK
;
113 if ((tx_done
->status
== HTT_TX_COMPL_STATE_ACK
) &&
114 ((info
->flags
& IEEE80211_TX_CTL_NO_ACK
) ||
115 (flags
& ATH10K_SKB_F_NOACK_TID
)))
116 info
->flags
|= IEEE80211_TX_STAT_NOACK_TRANSMITTED
;
118 if (tx_done
->status
== HTT_TX_COMPL_STATE_DISCARD
) {
119 if ((info
->flags
& IEEE80211_TX_CTL_NO_ACK
) ||
120 (flags
& ATH10K_SKB_F_NOACK_TID
))
121 info
->flags
&= ~IEEE80211_TX_STAT_NOACK_TRANSMITTED
;
123 info
->flags
&= ~IEEE80211_TX_STAT_ACK
;
126 if (tx_done
->status
== HTT_TX_COMPL_STATE_ACK
&&
127 tx_done
->ack_rssi
!= ATH10K_INVALID_RSSI
) {
128 info
->status
.ack_signal
= ATH10K_DEFAULT_NOISE_FLOOR
+
130 info
->status
.is_valid_ack_signal
= true;
133 ieee80211_tx_status(htt
->ar
->hw
, msdu
);
134 /* we do not own the msdu anymore */
139 struct ath10k_peer
*ath10k_peer_find(struct ath10k
*ar
, int vdev_id
,
142 struct ath10k_peer
*peer
;
144 lockdep_assert_held(&ar
->data_lock
);
146 list_for_each_entry(peer
, &ar
->peers
, list
) {
147 if (peer
->vdev_id
!= vdev_id
)
149 if (!ether_addr_equal(peer
->addr
, addr
))
158 struct ath10k_peer
*ath10k_peer_find_by_id(struct ath10k
*ar
, int peer_id
)
160 struct ath10k_peer
*peer
;
162 if (peer_id
>= BITS_PER_TYPE(peer
->peer_ids
))
165 lockdep_assert_held(&ar
->data_lock
);
167 list_for_each_entry(peer
, &ar
->peers
, list
)
168 if (test_bit(peer_id
, peer
->peer_ids
))
174 static int ath10k_wait_for_peer_common(struct ath10k
*ar
, int vdev_id
,
175 const u8
*addr
, bool expect_mapped
)
179 time_left
= wait_event_timeout(ar
->peer_mapping_wq
, ({
182 spin_lock_bh(&ar
->data_lock
);
183 mapped
= !!ath10k_peer_find(ar
, vdev_id
, addr
);
184 spin_unlock_bh(&ar
->data_lock
);
186 (mapped
== expect_mapped
||
187 test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
));
196 int ath10k_wait_for_peer_created(struct ath10k
*ar
, int vdev_id
, const u8
*addr
)
198 return ath10k_wait_for_peer_common(ar
, vdev_id
, addr
, true);
201 int ath10k_wait_for_peer_deleted(struct ath10k
*ar
, int vdev_id
, const u8
*addr
)
203 return ath10k_wait_for_peer_common(ar
, vdev_id
, addr
, false);
206 void ath10k_peer_map_event(struct ath10k_htt
*htt
,
207 struct htt_peer_map_event
*ev
)
209 struct ath10k
*ar
= htt
->ar
;
210 struct ath10k_peer
*peer
;
212 if (ev
->peer_id
>= ATH10K_MAX_NUM_PEER_IDS
) {
214 "received htt peer map event with idx out of bounds: %hu\n",
219 spin_lock_bh(&ar
->data_lock
);
220 peer
= ath10k_peer_find(ar
, ev
->vdev_id
, ev
->addr
);
222 peer
= kzalloc(sizeof(*peer
), GFP_ATOMIC
);
226 peer
->vdev_id
= ev
->vdev_id
;
227 ether_addr_copy(peer
->addr
, ev
->addr
);
228 list_add(&peer
->list
, &ar
->peers
);
229 wake_up(&ar
->peer_mapping_wq
);
232 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt peer map vdev %d peer %pM id %d\n",
233 ev
->vdev_id
, ev
->addr
, ev
->peer_id
);
235 WARN_ON(ar
->peer_map
[ev
->peer_id
] && (ar
->peer_map
[ev
->peer_id
] != peer
));
236 ar
->peer_map
[ev
->peer_id
] = peer
;
237 set_bit(ev
->peer_id
, peer
->peer_ids
);
239 spin_unlock_bh(&ar
->data_lock
);
242 void ath10k_peer_unmap_event(struct ath10k_htt
*htt
,
243 struct htt_peer_unmap_event
*ev
)
245 struct ath10k
*ar
= htt
->ar
;
246 struct ath10k_peer
*peer
;
248 if (ev
->peer_id
>= ATH10K_MAX_NUM_PEER_IDS
) {
250 "received htt peer unmap event with idx out of bounds: %hu\n",
255 spin_lock_bh(&ar
->data_lock
);
256 peer
= ath10k_peer_find_by_id(ar
, ev
->peer_id
);
258 ath10k_warn(ar
, "peer-unmap-event: unknown peer id %d\n",
263 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt peer unmap vdev %d peer %pM id %d\n",
264 peer
->vdev_id
, peer
->addr
, ev
->peer_id
);
266 ar
->peer_map
[ev
->peer_id
] = NULL
;
267 clear_bit(ev
->peer_id
, peer
->peer_ids
);
269 if (bitmap_empty(peer
->peer_ids
, ATH10K_MAX_NUM_PEER_IDS
)) {
270 list_del(&peer
->list
);
272 wake_up(&ar
->peer_mapping_wq
);
276 spin_unlock_bh(&ar
->data_lock
);