1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Data transmitting implementation.
4  *
5  * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
6  * Copyright (c) 2010, ST-Ericsson
7  */
8 #include <net/mac80211.h>
9 #include <linux/etherdevice.h>
10 
11 #include "data_tx.h"
12 #include "wfx.h"
13 #include "bh.h"
14 #include "sta.h"
15 #include "queue.h"
16 #include "debug.h"
17 #include "traces.h"
18 #include "hif_tx_mib.h"
19 
20 static int wfx_get_hw_rate(struct wfx_dev *wdev, const struct ieee80211_tx_rate *rate)
21 {
22 	struct ieee80211_supported_band *band;
23 
24 	if (rate->idx < 0)
25 		return -1;
26 	if (rate->flags & IEEE80211_TX_RC_MCS) {
27 		if (rate->idx > 7) {
28 			WARN(1, "wrong rate->idx value: %d", rate->idx);
29 			return -1;
30 		}
31 		return rate->idx + 14;
32 	}
33 	/* The device only support 2GHz, else band information should be retrieved from
34 	 * ieee80211_tx_info
35 	 */
36 	band = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];
37 	if (rate->idx >= band->n_bitrates) {
38 		WARN(1, "wrong rate->idx value: %d", rate->idx);
39 		return -1;
40 	}
41 	return band->bitrates[rate->idx].hw_value;
42 }
43 
44 /* TX policy cache implementation */
45 
46 static void wfx_tx_policy_build(struct wfx_vif *wvif, struct wfx_tx_policy *policy,
47 				struct ieee80211_tx_rate *rates)
48 {
49 	struct wfx_dev *wdev = wvif->wdev;
50 	int i, rateid;
51 	u8 count;
52 
53 	WARN(rates[0].idx < 0, "invalid rate policy");
54 	memset(policy, 0, sizeof(*policy));
55 	for (i = 0; i < IEEE80211_TX_MAX_RATES; ++i) {
56 		if (rates[i].idx < 0)
57 			break;
58 		WARN_ON(rates[i].count > 15);
59 		rateid = wfx_get_hw_rate(wdev, &rates[i]);
60 		/* Pack two values in each byte of policy->rates */
61 		count = rates[i].count;
62 		if (rateid % 2)
63 			count <<= 4;
64 		policy->rates[rateid / 2] |= count;
65 	}
66 }
67 
68 static bool wfx_tx_policy_is_equal(const struct wfx_tx_policy *a, const struct wfx_tx_policy *b)
69 {
70 	return !memcmp(a->rates, b->rates, sizeof(a->rates));
71 }
72 
73 static int wfx_tx_policy_find(struct wfx_tx_policy_cache *cache, struct wfx_tx_policy *wanted)
74 {
75 	struct wfx_tx_policy *it;
76 
77 	list_for_each_entry(it, &cache->used, link)
78 		if (wfx_tx_policy_is_equal(wanted, it))
79 			return it - cache->cache;
80 	list_for_each_entry(it, &cache->free, link)
81 		if (wfx_tx_policy_is_equal(wanted, it))
82 			return it - cache->cache;
83 	return -1;
84 }
85 
86 static void wfx_tx_policy_use(struct wfx_tx_policy_cache *cache, struct wfx_tx_policy *entry)
87 {
88 	++entry->usage_count;
89 	list_move(&entry->link, &cache->used);
90 }
91 
92 static int wfx_tx_policy_release(struct wfx_tx_policy_cache *cache, struct wfx_tx_policy *entry)
93 {
94 	int ret = --entry->usage_count;
95 
96 	if (!ret)
97 		list_move(&entry->link, &cache->free);
98 	return ret;
99 }
100 
101 static int wfx_tx_policy_get(struct wfx_vif *wvif, struct ieee80211_tx_rate *rates, bool *renew)
102 {
103 	int idx;
104 	struct wfx_tx_policy_cache *cache = &wvif->tx_policy_cache;
105 	struct wfx_tx_policy wanted;
106 	struct wfx_tx_policy *entry;
107 
108 	wfx_tx_policy_build(wvif, &wanted, rates);
109 
110 	spin_lock_bh(&cache->lock);
111 	if (list_empty(&cache->free)) {
112 		WARN(1, "unable to get a valid Tx policy");
113 		spin_unlock_bh(&cache->lock);
114 		return HIF_TX_RETRY_POLICY_INVALID;
115 	}
116 	idx = wfx_tx_policy_find(cache, &wanted);
117 	if (idx >= 0) {
118 		*renew = false;
119 	} else {
120 		/* If policy is not found create a new one using the oldest entry in "free" list */
121 		*renew = true;
122 		entry = list_entry(cache->free.prev, struct wfx_tx_policy, link);
123 		memcpy(entry->rates, wanted.rates, sizeof(entry->rates));
124 		entry->uploaded = false;
125 		entry->usage_count = 0;
126 		idx = entry - cache->cache;
127 	}
128 	wfx_tx_policy_use(cache, &cache->cache[idx]);
129 	if (list_empty(&cache->free))
130 		ieee80211_stop_queues(wvif->wdev->hw);
131 	spin_unlock_bh(&cache->lock);
132 	return idx;
133 }
134 
135 static void wfx_tx_policy_put(struct wfx_vif *wvif, int idx)
136 {
137 	int usage, locked;
138 	struct wfx_tx_policy_cache *cache = &wvif->tx_policy_cache;
139 
140 	if (idx == HIF_TX_RETRY_POLICY_INVALID)
141 		return;
142 	spin_lock_bh(&cache->lock);
143 	locked = list_empty(&cache->free);
144 	usage = wfx_tx_policy_release(cache, &cache->cache[idx]);
145 	if (locked && !usage)
146 		ieee80211_wake_queues(wvif->wdev->hw);
147 	spin_unlock_bh(&cache->lock);
148 }
149 
150 static int wfx_tx_policy_upload(struct wfx_vif *wvif)
151 {
152 	struct wfx_tx_policy *policies = wvif->tx_policy_cache.cache;
153 	u8 tmp_rates[12];
154 	int i, is_used;
155 
156 	do {
157 		spin_lock_bh(&wvif->tx_policy_cache.lock);
158 		for (i = 0; i < ARRAY_SIZE(wvif->tx_policy_cache.cache); ++i) {
159 			is_used = memzcmp(policies[i].rates, sizeof(policies[i].rates));
160 			if (!policies[i].uploaded && is_used)
161 				break;
162 		}
163 		if (i < ARRAY_SIZE(wvif->tx_policy_cache.cache)) {
164 			policies[i].uploaded = true;
165 			memcpy(tmp_rates, policies[i].rates, sizeof(tmp_rates));
166 			spin_unlock_bh(&wvif->tx_policy_cache.lock);
167 			wfx_hif_set_tx_rate_retry_policy(wvif, i, tmp_rates);
168 		} else {
169 			spin_unlock_bh(&wvif->tx_policy_cache.lock);
170 		}
171 	} while (i < ARRAY_SIZE(wvif->tx_policy_cache.cache));
172 	return 0;
173 }
174 
175 void wfx_tx_policy_upload_work(struct work_struct *work)
176 {
177 	struct wfx_vif *wvif = container_of(work, struct wfx_vif, tx_policy_upload_work);
178 
179 	wfx_tx_policy_upload(wvif);
180 	wfx_tx_unlock(wvif->wdev);
181 }
182 
183 void wfx_tx_policy_init(struct wfx_vif *wvif)
184 {
185 	struct wfx_tx_policy_cache *cache = &wvif->tx_policy_cache;
186 	int i;
187 
188 	memset(cache, 0, sizeof(*cache));
189 
190 	spin_lock_init(&cache->lock);
191 	INIT_LIST_HEAD(&cache->used);
192 	INIT_LIST_HEAD(&cache->free);
193 
194 	for (i = 0; i < ARRAY_SIZE(cache->cache); ++i)
195 		list_add(&cache->cache[i].link, &cache->free);
196 }
197 
198 /* Tx implementation */
199 
200 static bool wfx_is_action_back(struct ieee80211_hdr *hdr)
201 {
202 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
203 
204 	if (!ieee80211_is_action(mgmt->frame_control))
205 		return false;
206 	if (mgmt->u.action.category != WLAN_CATEGORY_BACK)
207 		return false;
208 	return true;
209 }
210 
211 static u8 wfx_tx_get_link_id(struct wfx_vif *wvif, struct ieee80211_sta *sta,
212 			     struct ieee80211_hdr *hdr)
213 {
214 	struct wfx_sta_priv *sta_priv = sta ? (struct wfx_sta_priv *)&sta->drv_priv : NULL;
215 	const u8 *da = ieee80211_get_DA(hdr);
216 
217 	if (sta_priv && sta_priv->link_id)
218 		return sta_priv->link_id;
219 	if (wvif->vif->type != NL80211_IFTYPE_AP)
220 		return 0;
221 	if (is_multicast_ether_addr(da))
222 		return 0;
223 	return HIF_LINK_ID_NOT_ASSOCIATED;
224 }
225 
226 static void wfx_tx_fixup_rates(struct ieee80211_tx_rate *rates)
227 {
228 	int i;
229 	bool finished;
230 
231 	/* Firmware is not able to mix rates with different flags */
232 	for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
233 		if (rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
234 			rates[i].flags |= IEEE80211_TX_RC_SHORT_GI;
235 		if (!(rates[0].flags & IEEE80211_TX_RC_SHORT_GI))
236 			rates[i].flags &= ~IEEE80211_TX_RC_SHORT_GI;
237 		if (!(rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS))
238 			rates[i].flags &= ~IEEE80211_TX_RC_USE_RTS_CTS;
239 	}
240 
241 	/* Sort rates and remove duplicates */
242 	do {
243 		finished = true;
244 		for (i = 0; i < IEEE80211_TX_MAX_RATES - 1; i++) {
245 			if (rates[i + 1].idx == rates[i].idx &&
246 			    rates[i].idx != -1) {
247 				rates[i].count += rates[i + 1].count;
248 				if (rates[i].count > 15)
249 					rates[i].count = 15;
250 				rates[i + 1].idx = -1;
251 				rates[i + 1].count = 0;
252 
253 				finished = false;
254 			}
255 			if (rates[i + 1].idx > rates[i].idx) {
256 				swap(rates[i + 1], rates[i]);
257 				finished = false;
258 			}
259 		}
260 	} while (!finished);
261 	/* Ensure that MCS0 or 1Mbps is present at the end of the retry list */
262 	for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
263 		if (rates[i].idx == 0)
264 			break;
265 		if (rates[i].idx == -1) {
266 			rates[i].idx = 0;
267 			rates[i].count = 8; /* == hw->max_rate_tries */
268 			rates[i].flags = rates[i - 1].flags & IEEE80211_TX_RC_MCS;
269 			break;
270 		}
271 	}
272 	/* All retries use long GI */
273 	for (i = 1; i < IEEE80211_TX_MAX_RATES; i++)
274 		rates[i].flags &= ~IEEE80211_TX_RC_SHORT_GI;
275 }
276 
277 static u8 wfx_tx_get_retry_policy_id(struct wfx_vif *wvif, struct ieee80211_tx_info *tx_info)
278 {
279 	bool tx_policy_renew = false;
280 	u8 ret;
281 
282 	ret = wfx_tx_policy_get(wvif, tx_info->driver_rates, &tx_policy_renew);
283 	if (ret == HIF_TX_RETRY_POLICY_INVALID)
284 		dev_warn(wvif->wdev->dev, "unable to get a valid Tx policy");
285 
286 	if (tx_policy_renew) {
287 		wfx_tx_lock(wvif->wdev);
288 		if (!schedule_work(&wvif->tx_policy_upload_work))
289 			wfx_tx_unlock(wvif->wdev);
290 	}
291 	return ret;
292 }
293 
294 static int wfx_tx_get_frame_format(struct ieee80211_tx_info *tx_info)
295 {
296 	if (!(tx_info->driver_rates[0].flags & IEEE80211_TX_RC_MCS))
297 		return HIF_FRAME_FORMAT_NON_HT;
298 	else if (!(tx_info->driver_rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD))
299 		return HIF_FRAME_FORMAT_MIXED_FORMAT_HT;
300 	else
301 		return HIF_FRAME_FORMAT_GF_HT_11N;
302 }
303 
304 static int wfx_tx_get_icv_len(struct ieee80211_key_conf *hw_key)
305 {
306 	int mic_space;
307 
308 	if (!hw_key)
309 		return 0;
310 	if (hw_key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
311 		return 0;
312 	mic_space = (hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) ? 8 : 0;
313 	return hw_key->icv_len + mic_space;
314 }
315 
316 static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, struct sk_buff *skb)
317 {
318 	struct wfx_hif_msg *hif_msg;
319 	struct wfx_hif_req_tx *req;
320 	struct wfx_tx_priv *tx_priv;
321 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
322 	struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
323 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
324 	int queue_id = skb_get_queue_mapping(skb);
325 	size_t offset = (size_t)skb->data & 3;
326 	int wmsg_len = sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_req_tx) + offset;
327 
328 	WARN(queue_id >= IEEE80211_NUM_ACS, "unsupported queue_id");
329 	wfx_tx_fixup_rates(tx_info->driver_rates);
330 
331 	/* From now tx_info->control is unusable */
332 	memset(tx_info->rate_driver_data, 0, sizeof(struct wfx_tx_priv));
333 	/* Fill tx_priv */
334 	tx_priv = (struct wfx_tx_priv *)tx_info->rate_driver_data;
335 	tx_priv->icv_size = wfx_tx_get_icv_len(hw_key);
336 
337 	/* Fill hif_msg */
338 	WARN(skb_headroom(skb) < wmsg_len, "not enough space in skb");
339 	WARN(offset & 1, "attempt to transmit an unaligned frame");
340 	skb_put(skb, tx_priv->icv_size);
341 	skb_push(skb, wmsg_len);
342 	memset(skb->data, 0, wmsg_len);
343 	hif_msg = (struct wfx_hif_msg *)skb->data;
344 	hif_msg->len = cpu_to_le16(skb->len);
345 	hif_msg->id = HIF_REQ_ID_TX;
346 	hif_msg->interface = wvif->id;
347 	if (skb->len > le16_to_cpu(wvif->wdev->hw_caps.size_inp_ch_buf)) {
348 		dev_warn(wvif->wdev->dev,
349 			 "requested frame size (%d) is larger than maximum supported (%d)\n",
350 			 skb->len, le16_to_cpu(wvif->wdev->hw_caps.size_inp_ch_buf));
351 		skb_pull(skb, wmsg_len);
352 		return -EIO;
353 	}
354 
355 	/* Fill tx request */
356 	req = (struct wfx_hif_req_tx *)hif_msg->body;
357 	/* packet_id just need to be unique on device. 32bits are more than necessary for that task,
358 	 * so we take advantage of it to add some extra data for debug.
359 	 */
360 	req->packet_id = atomic_add_return(1, &wvif->wdev->packet_id) & 0xFFFF;
361 	req->packet_id |= IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)) << 16;
362 	req->packet_id |= queue_id << 28;
363 
364 	req->fc_offset = offset;
365 	/* Queue index are inverted between firmware and Linux */
366 	req->queue_id = 3 - queue_id;
367 	req->peer_sta_id = wfx_tx_get_link_id(wvif, sta, hdr);
368 	req->retry_policy_index = wfx_tx_get_retry_policy_id(wvif, tx_info);
369 	req->frame_format = wfx_tx_get_frame_format(tx_info);
370 	if (tx_info->driver_rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
371 		req->short_gi = 1;
372 	if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM)
373 		req->after_dtim = 1;
374 
375 	/* Auxiliary operations */
376 	wfx_tx_queues_put(wvif, skb);
377 	if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM)
378 		schedule_work(&wvif->update_tim_work);
379 	wfx_bh_request_tx(wvif->wdev);
380 	return 0;
381 }
382 
383 void wfx_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb)
384 {
385 	struct wfx_dev *wdev = hw->priv;
386 	struct wfx_vif *wvif;
387 	struct ieee80211_sta *sta = control ? control->sta : NULL;
388 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
389 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
390 	size_t driver_data_room = sizeof_field(struct ieee80211_tx_info, rate_driver_data);
391 
392 	BUILD_BUG_ON_MSG(sizeof(struct wfx_tx_priv) > driver_data_room,
393 			 "struct tx_priv is too large");
394 	WARN(skb->next || skb->prev, "skb is already member of a list");
395 	/* control.vif can be NULL for injected frames */
396 	if (tx_info->control.vif)
397 		wvif = (struct wfx_vif *)tx_info->control.vif->drv_priv;
398 	else
399 		wvif = wvif_iterate(wdev, NULL);
400 	if (WARN_ON(!wvif))
401 		goto drop;
402 	/* Because of TX_AMPDU_SETUP_IN_HW, mac80211 does not try to send any BlockAck session
403 	 * management frame. The check below exist just in case.
404 	 */
405 	if (wfx_is_action_back(hdr)) {
406 		dev_info(wdev->dev, "drop BA action\n");
407 		goto drop;
408 	}
409 	if (wfx_tx_inner(wvif, sta, skb))
410 		goto drop;
411 
412 	return;
413 
414 drop:
415 	ieee80211_tx_status_irqsafe(wdev->hw, skb);
416 }
417 
418 static void wfx_skb_dtor(struct wfx_vif *wvif, struct sk_buff *skb)
419 {
420 	struct wfx_hif_msg *hif = (struct wfx_hif_msg *)skb->data;
421 	struct wfx_hif_req_tx *req = (struct wfx_hif_req_tx *)hif->body;
422 	unsigned int offset = sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_req_tx) +
423 			      req->fc_offset;
424 
425 	if (!wvif) {
426 		pr_warn("vif associated with the skb does not exist anymore\n");
427 		return;
428 	}
429 	wfx_tx_policy_put(wvif, req->retry_policy_index);
430 	skb_pull(skb, offset);
431 	ieee80211_tx_status_irqsafe(wvif->wdev->hw, skb);
432 }
433 
434 static void wfx_tx_fill_rates(struct wfx_dev *wdev, struct ieee80211_tx_info *tx_info,
435 			      const struct wfx_hif_cnf_tx *arg)
436 {
437 	struct ieee80211_tx_rate *rate;
438 	int tx_count;
439 	int i;
440 
441 	tx_count = arg->ack_failures;
442 	if (!arg->status || arg->ack_failures)
443 		tx_count += 1; /* Also report success */
444 	for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
445 		rate = &tx_info->status.rates[i];
446 		if (rate->idx < 0)
447 			break;
448 		if (tx_count < rate->count && arg->status == HIF_STATUS_TX_FAIL_RETRIES &&
449 		    arg->ack_failures)
450 			dev_dbg(wdev->dev, "all retries were not consumed: %d != %d\n",
451 				rate->count, tx_count);
452 		if (tx_count <= rate->count && tx_count &&
453 		    arg->txed_rate != wfx_get_hw_rate(wdev, rate))
454 			dev_dbg(wdev->dev, "inconsistent tx_info rates: %d != %d\n",
455 				arg->txed_rate, wfx_get_hw_rate(wdev, rate));
456 		if (tx_count > rate->count) {
457 			tx_count -= rate->count;
458 		} else if (!tx_count) {
459 			rate->count = 0;
460 			rate->idx = -1;
461 		} else {
462 			rate->count = tx_count;
463 			tx_count = 0;
464 		}
465 	}
466 	if (tx_count)
467 		dev_dbg(wdev->dev, "%d more retries than expected\n", tx_count);
468 }
469 
470 void wfx_tx_confirm_cb(struct wfx_dev *wdev, const struct wfx_hif_cnf_tx *arg)
471 {
472 	const struct wfx_tx_priv *tx_priv;
473 	struct ieee80211_tx_info *tx_info;
474 	struct wfx_vif *wvif;
475 	struct sk_buff *skb;
476 
477 	skb = wfx_pending_get(wdev, arg->packet_id);
478 	if (!skb) {
479 		dev_warn(wdev->dev, "received unknown packet_id (%#.8x) from chip\n",
480 			 arg->packet_id);
481 		return;
482 	}
483 	tx_info = IEEE80211_SKB_CB(skb);
484 	tx_priv = wfx_skb_tx_priv(skb);
485 	wvif = wdev_to_wvif(wdev, ((struct wfx_hif_msg *)skb->data)->interface);
486 	WARN_ON(!wvif);
487 	if (!wvif)
488 		return;
489 
490 	/* Note that wfx_pending_get_pkt_us_delay() get data from tx_info */
491 	_trace_tx_stats(arg, skb, wfx_pending_get_pkt_us_delay(wdev, skb));
492 	wfx_tx_fill_rates(wdev, tx_info, arg);
493 	skb_trim(skb, skb->len - tx_priv->icv_size);
494 
495 	/* From now, you can touch to tx_info->status, but do not touch to tx_priv anymore */
496 	/* FIXME: use ieee80211_tx_info_clear_status() */
497 	memset(tx_info->rate_driver_data, 0, sizeof(tx_info->rate_driver_data));
498 	memset(tx_info->pad, 0, sizeof(tx_info->pad));
499 
500 	if (!arg->status) {
501 		tx_info->status.tx_time = le32_to_cpu(arg->media_delay) -
502 					  le32_to_cpu(arg->tx_queue_delay);
503 		if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
504 			tx_info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
505 		else
506 			tx_info->flags |= IEEE80211_TX_STAT_ACK;
507 	} else if (arg->status == HIF_STATUS_TX_FAIL_REQUEUE) {
508 		WARN(!arg->requeue, "incoherent status and result_flags");
509 		if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
510 			wvif->after_dtim_tx_allowed = false; /* DTIM period elapsed */
511 			schedule_work(&wvif->update_tim_work);
512 		}
513 		tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
514 	}
515 	wfx_skb_dtor(wvif, skb);
516 }
517 
518 static void wfx_flush_vif(struct wfx_vif *wvif, u32 queues, struct sk_buff_head *dropped)
519 {
520 	struct wfx_queue *queue;
521 	int i;
522 
523 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
524 		if (!(BIT(i) & queues))
525 			continue;
526 		queue = &wvif->tx_queue[i];
527 		if (dropped)
528 			wfx_tx_queue_drop(wvif, queue, dropped);
529 	}
530 	if (wvif->wdev->chip_frozen)
531 		return;
532 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
533 		if (!(BIT(i) & queues))
534 			continue;
535 		queue = &wvif->tx_queue[i];
536 		if (wait_event_timeout(wvif->wdev->tx_dequeue, wfx_tx_queue_empty(wvif, queue),
537 				       msecs_to_jiffies(1000)) <= 0)
538 			dev_warn(wvif->wdev->dev, "frames queued while flushing tx queues?");
539 	}
540 }
541 
542 void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u32 queues, bool drop)
543 {
544 	struct wfx_dev *wdev = hw->priv;
545 	struct sk_buff_head dropped;
546 	struct wfx_vif *wvif;
547 	struct wfx_hif_msg *hif;
548 	struct sk_buff *skb;
549 
550 	skb_queue_head_init(&dropped);
551 	if (vif) {
552 		wvif = (struct wfx_vif *)vif->drv_priv;
553 		wfx_flush_vif(wvif, queues, drop ? &dropped : NULL);
554 	} else {
555 		wvif = NULL;
556 		while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
557 			wfx_flush_vif(wvif, queues, drop ? &dropped : NULL);
558 	}
559 	wfx_tx_flush(wdev);
560 	if (wdev->chip_frozen)
561 		wfx_pending_drop(wdev, &dropped);
562 	while ((skb = skb_dequeue(&dropped)) != NULL) {
563 		hif = (struct wfx_hif_msg *)skb->data;
564 		wvif = wdev_to_wvif(wdev, hif->interface);
565 		ieee80211_tx_info_clear_status(IEEE80211_SKB_CB(skb));
566 		wfx_skb_dtor(wvif, skb);
567 	}
568 }
569