2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2016 Qualcomm Atheros, Inc.
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.
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.
24 static void ath10k_report_offchan_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
26 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
28 if (likely(!(info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
)))
31 if (ath10k_mac_tx_frm_has_freq(ar
))
34 /* If the original wait_for_completion() timed out before
35 * {data,mgmt}_tx_completed() was called then we could complete
36 * offchan_tx_completed for a different skb. Prevent this by using
39 spin_lock_bh(&ar
->data_lock
);
40 if (ar
->offchan_tx_skb
!= skb
) {
41 ath10k_warn(ar
, "completed old offchannel frame\n");
45 complete(&ar
->offchan_tx_completed
);
46 ar
->offchan_tx_skb
= NULL
; /* just for sanity */
48 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "completed offchannel skb %pK\n", skb
);
50 spin_unlock_bh(&ar
->data_lock
);
53 int ath10k_txrx_tx_unref(struct ath10k_htt
*htt
,
54 const struct htt_tx_done
*tx_done
)
56 struct ath10k
*ar
= htt
->ar
;
57 struct device
*dev
= ar
->dev
;
58 struct ieee80211_tx_info
*info
;
59 struct ieee80211_txq
*txq
;
60 struct ath10k_skb_cb
*skb_cb
;
61 struct ath10k_txq
*artxq
;
64 ath10k_dbg(ar
, ATH10K_DBG_HTT
,
65 "htt tx completion msdu_id %u status %d\n",
66 tx_done
->msdu_id
, tx_done
->status
);
68 if (tx_done
->msdu_id
>= htt
->max_num_pending_tx
) {
69 ath10k_warn(ar
, "warning: msdu_id %d too big, ignoring\n",
74 spin_lock_bh(&htt
->tx_lock
);
75 msdu
= idr_find(&htt
->pending_tx
, tx_done
->msdu_id
);
77 ath10k_warn(ar
, "received tx completion for invalid msdu_id: %d\n",
79 spin_unlock_bh(&htt
->tx_lock
);
83 skb_cb
= ATH10K_SKB_CB(msdu
);
87 artxq
= (void *)txq
->drv_priv
;
88 artxq
->num_fw_queued
--;
91 ath10k_htt_tx_free_msdu_id(htt
, tx_done
->msdu_id
);
92 ath10k_htt_tx_dec_pending(htt
);
93 if (htt
->num_pending_tx
== 0)
94 wake_up(&htt
->empty_tx_wq
);
95 spin_unlock_bh(&htt
->tx_lock
);
97 dma_unmap_single(dev
, skb_cb
->paddr
, msdu
->len
, DMA_TO_DEVICE
);
99 ath10k_report_offchan_tx(htt
->ar
, msdu
);
101 info
= IEEE80211_SKB_CB(msdu
);
102 memset(&info
->status
, 0, sizeof(info
->status
));
103 trace_ath10k_txrx_tx_unref(ar
, tx_done
->msdu_id
);
105 if (tx_done
->status
== HTT_TX_COMPL_STATE_DISCARD
) {
106 ieee80211_free_txskb(htt
->ar
->hw
, msdu
);
110 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
111 info
->flags
|= IEEE80211_TX_STAT_ACK
;
113 if (tx_done
->status
== HTT_TX_COMPL_STATE_NOACK
)
114 info
->flags
&= ~IEEE80211_TX_STAT_ACK
;
116 if ((tx_done
->status
== HTT_TX_COMPL_STATE_ACK
) &&
117 (info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
118 info
->flags
|= IEEE80211_TX_STAT_NOACK_TRANSMITTED
;
120 ieee80211_tx_status(htt
->ar
->hw
, msdu
);
121 /* we do not own the msdu anymore */
126 struct ath10k_peer
*ath10k_peer_find(struct ath10k
*ar
, int vdev_id
,
129 struct ath10k_peer
*peer
;
131 lockdep_assert_held(&ar
->data_lock
);
133 list_for_each_entry(peer
, &ar
->peers
, list
) {
134 if (peer
->vdev_id
!= vdev_id
)
136 if (!ether_addr_equal(peer
->addr
, addr
))
145 struct ath10k_peer
*ath10k_peer_find_by_id(struct ath10k
*ar
, int peer_id
)
147 struct ath10k_peer
*peer
;
149 lockdep_assert_held(&ar
->data_lock
);
151 list_for_each_entry(peer
, &ar
->peers
, list
)
152 if (test_bit(peer_id
, peer
->peer_ids
))
158 static int ath10k_wait_for_peer_common(struct ath10k
*ar
, int vdev_id
,
159 const u8
*addr
, bool expect_mapped
)
163 time_left
= wait_event_timeout(ar
->peer_mapping_wq
, ({
166 spin_lock_bh(&ar
->data_lock
);
167 mapped
= !!ath10k_peer_find(ar
, vdev_id
, addr
);
168 spin_unlock_bh(&ar
->data_lock
);
170 (mapped
== expect_mapped
||
171 test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
));
180 int ath10k_wait_for_peer_created(struct ath10k
*ar
, int vdev_id
, const u8
*addr
)
182 return ath10k_wait_for_peer_common(ar
, vdev_id
, addr
, true);
185 int ath10k_wait_for_peer_deleted(struct ath10k
*ar
, int vdev_id
, const u8
*addr
)
187 return ath10k_wait_for_peer_common(ar
, vdev_id
, addr
, false);
190 void ath10k_peer_map_event(struct ath10k_htt
*htt
,
191 struct htt_peer_map_event
*ev
)
193 struct ath10k
*ar
= htt
->ar
;
194 struct ath10k_peer
*peer
;
196 if (ev
->peer_id
>= ATH10K_MAX_NUM_PEER_IDS
) {
198 "received htt peer map event with idx out of bounds: %hu\n",
203 spin_lock_bh(&ar
->data_lock
);
204 peer
= ath10k_peer_find(ar
, ev
->vdev_id
, ev
->addr
);
206 peer
= kzalloc(sizeof(*peer
), GFP_ATOMIC
);
210 peer
->vdev_id
= ev
->vdev_id
;
211 ether_addr_copy(peer
->addr
, ev
->addr
);
212 list_add(&peer
->list
, &ar
->peers
);
213 wake_up(&ar
->peer_mapping_wq
);
216 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt peer map vdev %d peer %pM id %d\n",
217 ev
->vdev_id
, ev
->addr
, ev
->peer_id
);
219 WARN_ON(ar
->peer_map
[ev
->peer_id
] && (ar
->peer_map
[ev
->peer_id
] != peer
));
220 ar
->peer_map
[ev
->peer_id
] = peer
;
221 set_bit(ev
->peer_id
, peer
->peer_ids
);
223 spin_unlock_bh(&ar
->data_lock
);
226 void ath10k_peer_unmap_event(struct ath10k_htt
*htt
,
227 struct htt_peer_unmap_event
*ev
)
229 struct ath10k
*ar
= htt
->ar
;
230 struct ath10k_peer
*peer
;
232 if (ev
->peer_id
>= ATH10K_MAX_NUM_PEER_IDS
) {
234 "received htt peer unmap event with idx out of bounds: %hu\n",
239 spin_lock_bh(&ar
->data_lock
);
240 peer
= ath10k_peer_find_by_id(ar
, ev
->peer_id
);
242 ath10k_warn(ar
, "peer-unmap-event: unknown peer id %d\n",
247 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt peer unmap vdev %d peer %pM id %d\n",
248 peer
->vdev_id
, peer
->addr
, ev
->peer_id
);
250 ar
->peer_map
[ev
->peer_id
] = NULL
;
251 clear_bit(ev
->peer_id
, peer
->peer_ids
);
253 if (bitmap_empty(peer
->peer_ids
, ATH10K_MAX_NUM_PEER_IDS
)) {
254 list_del(&peer
->list
);
256 wake_up(&ar
->peer_mapping_wq
);
260 spin_unlock_bh(&ar
->data_lock
);