xref: /linux/drivers/net/wireless/silabs/wfx/data_tx.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
14a5fb1bbSJérôme Pouiller // SPDX-License-Identifier: GPL-2.0-only
24a5fb1bbSJérôme Pouiller /*
34a5fb1bbSJérôme Pouiller  * Data transmitting implementation.
44a5fb1bbSJérôme Pouiller  *
54a5fb1bbSJérôme Pouiller  * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
64a5fb1bbSJérôme Pouiller  * Copyright (c) 2010, ST-Ericsson
74a5fb1bbSJérôme Pouiller  */
84a5fb1bbSJérôme Pouiller #include <net/mac80211.h>
94a5fb1bbSJérôme Pouiller #include <linux/etherdevice.h>
104a5fb1bbSJérôme Pouiller 
114a5fb1bbSJérôme Pouiller #include "data_tx.h"
124a5fb1bbSJérôme Pouiller #include "wfx.h"
134a5fb1bbSJérôme Pouiller #include "bh.h"
144a5fb1bbSJérôme Pouiller #include "sta.h"
154a5fb1bbSJérôme Pouiller #include "queue.h"
164a5fb1bbSJérôme Pouiller #include "debug.h"
174a5fb1bbSJérôme Pouiller #include "traces.h"
184a5fb1bbSJérôme Pouiller #include "hif_tx_mib.h"
194a5fb1bbSJérôme Pouiller 
wfx_get_hw_rate(struct wfx_dev * wdev,const struct ieee80211_tx_rate * rate)204a5fb1bbSJérôme Pouiller static int wfx_get_hw_rate(struct wfx_dev *wdev, const struct ieee80211_tx_rate *rate)
214a5fb1bbSJérôme Pouiller {
224a5fb1bbSJérôme Pouiller 	struct ieee80211_supported_band *band;
234a5fb1bbSJérôme Pouiller 
244a5fb1bbSJérôme Pouiller 	if (rate->idx < 0)
254a5fb1bbSJérôme Pouiller 		return -1;
264a5fb1bbSJérôme Pouiller 	if (rate->flags & IEEE80211_TX_RC_MCS) {
274a5fb1bbSJérôme Pouiller 		if (rate->idx > 7) {
284a5fb1bbSJérôme Pouiller 			WARN(1, "wrong rate->idx value: %d", rate->idx);
294a5fb1bbSJérôme Pouiller 			return -1;
304a5fb1bbSJérôme Pouiller 		}
314a5fb1bbSJérôme Pouiller 		return rate->idx + 14;
324a5fb1bbSJérôme Pouiller 	}
334a5fb1bbSJérôme Pouiller 	/* The device only support 2GHz, else band information should be retrieved from
344a5fb1bbSJérôme Pouiller 	 * ieee80211_tx_info
354a5fb1bbSJérôme Pouiller 	 */
364a5fb1bbSJérôme Pouiller 	band = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];
374a5fb1bbSJérôme Pouiller 	if (rate->idx >= band->n_bitrates) {
384a5fb1bbSJérôme Pouiller 		WARN(1, "wrong rate->idx value: %d", rate->idx);
394a5fb1bbSJérôme Pouiller 		return -1;
404a5fb1bbSJérôme Pouiller 	}
414a5fb1bbSJérôme Pouiller 	return band->bitrates[rate->idx].hw_value;
424a5fb1bbSJérôme Pouiller }
434a5fb1bbSJérôme Pouiller 
444a5fb1bbSJérôme Pouiller /* TX policy cache implementation */
454a5fb1bbSJérôme Pouiller 
wfx_tx_policy_build(struct wfx_vif * wvif,struct wfx_tx_policy * policy,struct ieee80211_tx_rate * rates)464a5fb1bbSJérôme Pouiller static void wfx_tx_policy_build(struct wfx_vif *wvif, struct wfx_tx_policy *policy,
474a5fb1bbSJérôme Pouiller 				struct ieee80211_tx_rate *rates)
484a5fb1bbSJérôme Pouiller {
494a5fb1bbSJérôme Pouiller 	struct wfx_dev *wdev = wvif->wdev;
504a5fb1bbSJérôme Pouiller 	int i, rateid;
514a5fb1bbSJérôme Pouiller 	u8 count;
524a5fb1bbSJérôme Pouiller 
534a5fb1bbSJérôme Pouiller 	WARN(rates[0].idx < 0, "invalid rate policy");
544a5fb1bbSJérôme Pouiller 	memset(policy, 0, sizeof(*policy));
554a5fb1bbSJérôme Pouiller 	for (i = 0; i < IEEE80211_TX_MAX_RATES; ++i) {
564a5fb1bbSJérôme Pouiller 		if (rates[i].idx < 0)
574a5fb1bbSJérôme Pouiller 			break;
584a5fb1bbSJérôme Pouiller 		WARN_ON(rates[i].count > 15);
594a5fb1bbSJérôme Pouiller 		rateid = wfx_get_hw_rate(wdev, &rates[i]);
604a5fb1bbSJérôme Pouiller 		/* Pack two values in each byte of policy->rates */
614a5fb1bbSJérôme Pouiller 		count = rates[i].count;
624a5fb1bbSJérôme Pouiller 		if (rateid % 2)
634a5fb1bbSJérôme Pouiller 			count <<= 4;
644a5fb1bbSJérôme Pouiller 		policy->rates[rateid / 2] |= count;
654a5fb1bbSJérôme Pouiller 	}
664a5fb1bbSJérôme Pouiller }
674a5fb1bbSJérôme Pouiller 
wfx_tx_policy_is_equal(const struct wfx_tx_policy * a,const struct wfx_tx_policy * b)684a5fb1bbSJérôme Pouiller static bool wfx_tx_policy_is_equal(const struct wfx_tx_policy *a, const struct wfx_tx_policy *b)
694a5fb1bbSJérôme Pouiller {
704a5fb1bbSJérôme Pouiller 	return !memcmp(a->rates, b->rates, sizeof(a->rates));
714a5fb1bbSJérôme Pouiller }
724a5fb1bbSJérôme Pouiller 
wfx_tx_policy_find(struct wfx_tx_policy_cache * cache,struct wfx_tx_policy * wanted)734a5fb1bbSJérôme Pouiller static int wfx_tx_policy_find(struct wfx_tx_policy_cache *cache, struct wfx_tx_policy *wanted)
744a5fb1bbSJérôme Pouiller {
754a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy *it;
764a5fb1bbSJérôme Pouiller 
774a5fb1bbSJérôme Pouiller 	list_for_each_entry(it, &cache->used, link)
784a5fb1bbSJérôme Pouiller 		if (wfx_tx_policy_is_equal(wanted, it))
794a5fb1bbSJérôme Pouiller 			return it - cache->cache;
804a5fb1bbSJérôme Pouiller 	list_for_each_entry(it, &cache->free, link)
814a5fb1bbSJérôme Pouiller 		if (wfx_tx_policy_is_equal(wanted, it))
824a5fb1bbSJérôme Pouiller 			return it - cache->cache;
834a5fb1bbSJérôme Pouiller 	return -1;
844a5fb1bbSJérôme Pouiller }
854a5fb1bbSJérôme Pouiller 
wfx_tx_policy_use(struct wfx_tx_policy_cache * cache,struct wfx_tx_policy * entry)864a5fb1bbSJérôme Pouiller static void wfx_tx_policy_use(struct wfx_tx_policy_cache *cache, struct wfx_tx_policy *entry)
874a5fb1bbSJérôme Pouiller {
884a5fb1bbSJérôme Pouiller 	++entry->usage_count;
894a5fb1bbSJérôme Pouiller 	list_move(&entry->link, &cache->used);
904a5fb1bbSJérôme Pouiller }
914a5fb1bbSJérôme Pouiller 
wfx_tx_policy_release(struct wfx_tx_policy_cache * cache,struct wfx_tx_policy * entry)924a5fb1bbSJérôme Pouiller static int wfx_tx_policy_release(struct wfx_tx_policy_cache *cache, struct wfx_tx_policy *entry)
934a5fb1bbSJérôme Pouiller {
944a5fb1bbSJérôme Pouiller 	int ret = --entry->usage_count;
954a5fb1bbSJérôme Pouiller 
964a5fb1bbSJérôme Pouiller 	if (!ret)
974a5fb1bbSJérôme Pouiller 		list_move(&entry->link, &cache->free);
984a5fb1bbSJérôme Pouiller 	return ret;
994a5fb1bbSJérôme Pouiller }
1004a5fb1bbSJérôme Pouiller 
wfx_tx_policy_get(struct wfx_vif * wvif,struct ieee80211_tx_rate * rates,bool * renew)1014a5fb1bbSJérôme Pouiller static int wfx_tx_policy_get(struct wfx_vif *wvif, struct ieee80211_tx_rate *rates, bool *renew)
1024a5fb1bbSJérôme Pouiller {
1034a5fb1bbSJérôme Pouiller 	int idx;
1044a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy_cache *cache = &wvif->tx_policy_cache;
1054a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy wanted;
1064a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy *entry;
1074a5fb1bbSJérôme Pouiller 
1084a5fb1bbSJérôme Pouiller 	wfx_tx_policy_build(wvif, &wanted, rates);
1094a5fb1bbSJérôme Pouiller 
1104a5fb1bbSJérôme Pouiller 	spin_lock_bh(&cache->lock);
1114a5fb1bbSJérôme Pouiller 	if (list_empty(&cache->free)) {
1124a5fb1bbSJérôme Pouiller 		WARN(1, "unable to get a valid Tx policy");
1134a5fb1bbSJérôme Pouiller 		spin_unlock_bh(&cache->lock);
1144a5fb1bbSJérôme Pouiller 		return HIF_TX_RETRY_POLICY_INVALID;
1154a5fb1bbSJérôme Pouiller 	}
1164a5fb1bbSJérôme Pouiller 	idx = wfx_tx_policy_find(cache, &wanted);
1174a5fb1bbSJérôme Pouiller 	if (idx >= 0) {
1184a5fb1bbSJérôme Pouiller 		*renew = false;
1194a5fb1bbSJérôme Pouiller 	} else {
1204a5fb1bbSJérôme Pouiller 		/* If policy is not found create a new one using the oldest entry in "free" list */
1214a5fb1bbSJérôme Pouiller 		*renew = true;
1224a5fb1bbSJérôme Pouiller 		entry = list_entry(cache->free.prev, struct wfx_tx_policy, link);
1234a5fb1bbSJérôme Pouiller 		memcpy(entry->rates, wanted.rates, sizeof(entry->rates));
1244a5fb1bbSJérôme Pouiller 		entry->uploaded = false;
1254a5fb1bbSJérôme Pouiller 		entry->usage_count = 0;
1264a5fb1bbSJérôme Pouiller 		idx = entry - cache->cache;
1274a5fb1bbSJérôme Pouiller 	}
1284a5fb1bbSJérôme Pouiller 	wfx_tx_policy_use(cache, &cache->cache[idx]);
1294a5fb1bbSJérôme Pouiller 	if (list_empty(&cache->free))
1304a5fb1bbSJérôme Pouiller 		ieee80211_stop_queues(wvif->wdev->hw);
1314a5fb1bbSJérôme Pouiller 	spin_unlock_bh(&cache->lock);
1324a5fb1bbSJérôme Pouiller 	return idx;
1334a5fb1bbSJérôme Pouiller }
1344a5fb1bbSJérôme Pouiller 
wfx_tx_policy_put(struct wfx_vif * wvif,int idx)1354a5fb1bbSJérôme Pouiller static void wfx_tx_policy_put(struct wfx_vif *wvif, int idx)
1364a5fb1bbSJérôme Pouiller {
1374a5fb1bbSJérôme Pouiller 	int usage, locked;
1384a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy_cache *cache = &wvif->tx_policy_cache;
1394a5fb1bbSJérôme Pouiller 
1404a5fb1bbSJérôme Pouiller 	if (idx == HIF_TX_RETRY_POLICY_INVALID)
1414a5fb1bbSJérôme Pouiller 		return;
1424a5fb1bbSJérôme Pouiller 	spin_lock_bh(&cache->lock);
1434a5fb1bbSJérôme Pouiller 	locked = list_empty(&cache->free);
1444a5fb1bbSJérôme Pouiller 	usage = wfx_tx_policy_release(cache, &cache->cache[idx]);
1454a5fb1bbSJérôme Pouiller 	if (locked && !usage)
1464a5fb1bbSJérôme Pouiller 		ieee80211_wake_queues(wvif->wdev->hw);
1474a5fb1bbSJérôme Pouiller 	spin_unlock_bh(&cache->lock);
1484a5fb1bbSJérôme Pouiller }
1494a5fb1bbSJérôme Pouiller 
wfx_tx_policy_upload(struct wfx_vif * wvif)1504a5fb1bbSJérôme Pouiller static int wfx_tx_policy_upload(struct wfx_vif *wvif)
1514a5fb1bbSJérôme Pouiller {
1524a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy *policies = wvif->tx_policy_cache.cache;
1534a5fb1bbSJérôme Pouiller 	u8 tmp_rates[12];
1544a5fb1bbSJérôme Pouiller 	int i, is_used;
1554a5fb1bbSJérôme Pouiller 
1564a5fb1bbSJérôme Pouiller 	do {
1574a5fb1bbSJérôme Pouiller 		spin_lock_bh(&wvif->tx_policy_cache.lock);
1584a5fb1bbSJérôme Pouiller 		for (i = 0; i < ARRAY_SIZE(wvif->tx_policy_cache.cache); ++i) {
1594a5fb1bbSJérôme Pouiller 			is_used = memzcmp(policies[i].rates, sizeof(policies[i].rates));
1604a5fb1bbSJérôme Pouiller 			if (!policies[i].uploaded && is_used)
1614a5fb1bbSJérôme Pouiller 				break;
1624a5fb1bbSJérôme Pouiller 		}
1634a5fb1bbSJérôme Pouiller 		if (i < ARRAY_SIZE(wvif->tx_policy_cache.cache)) {
1644a5fb1bbSJérôme Pouiller 			policies[i].uploaded = true;
1654a5fb1bbSJérôme Pouiller 			memcpy(tmp_rates, policies[i].rates, sizeof(tmp_rates));
1664a5fb1bbSJérôme Pouiller 			spin_unlock_bh(&wvif->tx_policy_cache.lock);
1674a5fb1bbSJérôme Pouiller 			wfx_hif_set_tx_rate_retry_policy(wvif, i, tmp_rates);
1684a5fb1bbSJérôme Pouiller 		} else {
1694a5fb1bbSJérôme Pouiller 			spin_unlock_bh(&wvif->tx_policy_cache.lock);
1704a5fb1bbSJérôme Pouiller 		}
1714a5fb1bbSJérôme Pouiller 	} while (i < ARRAY_SIZE(wvif->tx_policy_cache.cache));
1724a5fb1bbSJérôme Pouiller 	return 0;
1734a5fb1bbSJérôme Pouiller }
1744a5fb1bbSJérôme Pouiller 
wfx_tx_policy_upload_work(struct work_struct * work)1754a5fb1bbSJérôme Pouiller void wfx_tx_policy_upload_work(struct work_struct *work)
1764a5fb1bbSJérôme Pouiller {
1774a5fb1bbSJérôme Pouiller 	struct wfx_vif *wvif = container_of(work, struct wfx_vif, tx_policy_upload_work);
1784a5fb1bbSJérôme Pouiller 
1794a5fb1bbSJérôme Pouiller 	wfx_tx_policy_upload(wvif);
1804a5fb1bbSJérôme Pouiller 	wfx_tx_unlock(wvif->wdev);
1814a5fb1bbSJérôme Pouiller }
1824a5fb1bbSJérôme Pouiller 
wfx_tx_policy_init(struct wfx_vif * wvif)1834a5fb1bbSJérôme Pouiller void wfx_tx_policy_init(struct wfx_vif *wvif)
1844a5fb1bbSJérôme Pouiller {
1854a5fb1bbSJérôme Pouiller 	struct wfx_tx_policy_cache *cache = &wvif->tx_policy_cache;
1864a5fb1bbSJérôme Pouiller 	int i;
1874a5fb1bbSJérôme Pouiller 
1884a5fb1bbSJérôme Pouiller 	memset(cache, 0, sizeof(*cache));
1894a5fb1bbSJérôme Pouiller 
1904a5fb1bbSJérôme Pouiller 	spin_lock_init(&cache->lock);
1914a5fb1bbSJérôme Pouiller 	INIT_LIST_HEAD(&cache->used);
1924a5fb1bbSJérôme Pouiller 	INIT_LIST_HEAD(&cache->free);
1934a5fb1bbSJérôme Pouiller 
1944a5fb1bbSJérôme Pouiller 	for (i = 0; i < ARRAY_SIZE(cache->cache); ++i)
1954a5fb1bbSJérôme Pouiller 		list_add(&cache->cache[i].link, &cache->free);
1964a5fb1bbSJérôme Pouiller }
1974a5fb1bbSJérôme Pouiller 
1984a5fb1bbSJérôme Pouiller /* Tx implementation */
1994a5fb1bbSJérôme Pouiller 
wfx_is_action_back(struct ieee80211_hdr * hdr)2004a5fb1bbSJérôme Pouiller static bool wfx_is_action_back(struct ieee80211_hdr *hdr)
2014a5fb1bbSJérôme Pouiller {
2024a5fb1bbSJérôme Pouiller 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
2034a5fb1bbSJérôme Pouiller 
2044a5fb1bbSJérôme Pouiller 	if (!ieee80211_is_action(mgmt->frame_control))
2054a5fb1bbSJérôme Pouiller 		return false;
2064a5fb1bbSJérôme Pouiller 	if (mgmt->u.action.category != WLAN_CATEGORY_BACK)
2074a5fb1bbSJérôme Pouiller 		return false;
2084a5fb1bbSJérôme Pouiller 	return true;
2094a5fb1bbSJérôme Pouiller }
2104a5fb1bbSJérôme Pouiller 
wfx_skb_tx_priv(struct sk_buff * skb)211cf0cc05cSJérôme Pouiller struct wfx_tx_priv *wfx_skb_tx_priv(struct sk_buff *skb)
212cf0cc05cSJérôme Pouiller {
213cf0cc05cSJérôme Pouiller 	struct ieee80211_tx_info *tx_info;
214cf0cc05cSJérôme Pouiller 
215cf0cc05cSJérôme Pouiller 	if (!skb)
216cf0cc05cSJérôme Pouiller 		return NULL;
217cf0cc05cSJérôme Pouiller 	tx_info = IEEE80211_SKB_CB(skb);
218cf0cc05cSJérôme Pouiller 	return (struct wfx_tx_priv *)tx_info->rate_driver_data;
219cf0cc05cSJérôme Pouiller }
220cf0cc05cSJérôme Pouiller 
wfx_skb_txreq(struct sk_buff * skb)221cf0cc05cSJérôme Pouiller struct wfx_hif_req_tx *wfx_skb_txreq(struct sk_buff *skb)
222cf0cc05cSJérôme Pouiller {
223cf0cc05cSJérôme Pouiller 	struct wfx_hif_msg *hif = (struct wfx_hif_msg *)skb->data;
224cf0cc05cSJérôme Pouiller 	struct wfx_hif_req_tx *req = (struct wfx_hif_req_tx *)hif->body;
225cf0cc05cSJérôme Pouiller 
226cf0cc05cSJérôme Pouiller 	return req;
227cf0cc05cSJérôme Pouiller }
228cf0cc05cSJérôme Pouiller 
wfx_skb_wvif(struct wfx_dev * wdev,struct sk_buff * skb)229f7385a20SJérôme Pouiller struct wfx_vif *wfx_skb_wvif(struct wfx_dev *wdev, struct sk_buff *skb)
230f7385a20SJérôme Pouiller {
231f7385a20SJérôme Pouiller 	struct wfx_tx_priv *tx_priv = wfx_skb_tx_priv(skb);
232f7385a20SJérôme Pouiller 	struct wfx_hif_msg *hif = (struct wfx_hif_msg *)skb->data;
233f7385a20SJérôme Pouiller 
234f7385a20SJérôme Pouiller 	if (tx_priv->vif_id != hif->interface && hif->interface != 2) {
235f7385a20SJérôme Pouiller 		dev_err(wdev->dev, "corrupted skb");
236f7385a20SJérôme Pouiller 		return wdev_to_wvif(wdev, hif->interface);
237f7385a20SJérôme Pouiller 	}
238f7385a20SJérôme Pouiller 	return wdev_to_wvif(wdev, tx_priv->vif_id);
239f7385a20SJérôme Pouiller }
240f7385a20SJérôme Pouiller 
wfx_tx_get_link_id(struct wfx_vif * wvif,struct ieee80211_sta * sta,struct ieee80211_hdr * hdr)2414a5fb1bbSJérôme Pouiller static u8 wfx_tx_get_link_id(struct wfx_vif *wvif, struct ieee80211_sta *sta,
2424a5fb1bbSJérôme Pouiller 			     struct ieee80211_hdr *hdr)
2434a5fb1bbSJérôme Pouiller {
2444a5fb1bbSJérôme Pouiller 	struct wfx_sta_priv *sta_priv = sta ? (struct wfx_sta_priv *)&sta->drv_priv : NULL;
2452c33360bSJaehee Park 	struct ieee80211_vif *vif = wvif_to_vif(wvif);
2464a5fb1bbSJérôme Pouiller 	const u8 *da = ieee80211_get_DA(hdr);
2474a5fb1bbSJérôme Pouiller 
2484a5fb1bbSJérôme Pouiller 	if (sta_priv && sta_priv->link_id)
2494a5fb1bbSJérôme Pouiller 		return sta_priv->link_id;
2502c33360bSJaehee Park 	if (vif->type != NL80211_IFTYPE_AP)
2514a5fb1bbSJérôme Pouiller 		return 0;
2524a5fb1bbSJérôme Pouiller 	if (is_multicast_ether_addr(da))
2534a5fb1bbSJérôme Pouiller 		return 0;
2544a5fb1bbSJérôme Pouiller 	return HIF_LINK_ID_NOT_ASSOCIATED;
2554a5fb1bbSJérôme Pouiller }
2564a5fb1bbSJérôme Pouiller 
wfx_tx_fixup_rates(struct ieee80211_tx_rate * rates)2574a5fb1bbSJérôme Pouiller static void wfx_tx_fixup_rates(struct ieee80211_tx_rate *rates)
2584a5fb1bbSJérôme Pouiller {
259*ea2274abSFelipe Negrelli Wolter 	bool has_rate0 = false;
260*ea2274abSFelipe Negrelli Wolter 	int i, j;
2614a5fb1bbSJérôme Pouiller 
262*ea2274abSFelipe Negrelli Wolter 	for (i = 1, j = 1; j < IEEE80211_TX_MAX_RATES; j++) {
263*ea2274abSFelipe Negrelli Wolter 		if (rates[j].idx == -1)
2644a5fb1bbSJérôme Pouiller 			break;
265*ea2274abSFelipe Negrelli Wolter 		/* The device use the rates in descending order, whatever the request from minstrel.
266*ea2274abSFelipe Negrelli Wolter 		 * We have to trade off here. Most important is to respect the primary rate
267*ea2274abSFelipe Negrelli Wolter 		 * requested by minstrel. So, we drops the entries with rate higher than the
268*ea2274abSFelipe Negrelli Wolter 		 * previous.
269*ea2274abSFelipe Negrelli Wolter 		 */
270*ea2274abSFelipe Negrelli Wolter 		if (rates[j].idx >= rates[i - 1].idx) {
271*ea2274abSFelipe Negrelli Wolter 			rates[i - 1].count += rates[j].count;
272*ea2274abSFelipe Negrelli Wolter 			rates[i - 1].count = min_t(u16, 15, rates[i - 1].count);
273*ea2274abSFelipe Negrelli Wolter 		} else {
274*ea2274abSFelipe Negrelli Wolter 			memcpy(rates + i, rates + j, sizeof(rates[i]));
275*ea2274abSFelipe Negrelli Wolter 			if (rates[i].idx == 0)
276*ea2274abSFelipe Negrelli Wolter 				has_rate0 = true;
277*ea2274abSFelipe Negrelli Wolter 			/* The device apply Short GI only on the first rate */
278*ea2274abSFelipe Negrelli Wolter 			rates[i].flags &= ~IEEE80211_TX_RC_SHORT_GI;
279*ea2274abSFelipe Negrelli Wolter 			i++;
280*ea2274abSFelipe Negrelli Wolter 		}
281*ea2274abSFelipe Negrelli Wolter 	}
282*ea2274abSFelipe Negrelli Wolter 	/* Ensure that MCS0 or 1Mbps is present at the end of the retry list */
283*ea2274abSFelipe Negrelli Wolter 	if (!has_rate0 && i < IEEE80211_TX_MAX_RATES) {
2844a5fb1bbSJérôme Pouiller 		rates[i].idx = 0;
2854a5fb1bbSJérôme Pouiller 		rates[i].count = 8; /* == hw->max_rate_tries */
286*ea2274abSFelipe Negrelli Wolter 		rates[i].flags = rates[0].flags & IEEE80211_TX_RC_MCS;
287*ea2274abSFelipe Negrelli Wolter 		i++;
2884a5fb1bbSJérôme Pouiller 	}
289*ea2274abSFelipe Negrelli Wolter 	for (; i < IEEE80211_TX_MAX_RATES; i++) {
290*ea2274abSFelipe Negrelli Wolter 		memset(rates + i, 0, sizeof(rates[i]));
291*ea2274abSFelipe Negrelli Wolter 		rates[i].idx = -1;
2924a5fb1bbSJérôme Pouiller 	}
2934a5fb1bbSJérôme Pouiller }
2944a5fb1bbSJérôme Pouiller 
wfx_tx_get_retry_policy_id(struct wfx_vif * wvif,struct ieee80211_tx_info * tx_info)2954a5fb1bbSJérôme Pouiller static u8 wfx_tx_get_retry_policy_id(struct wfx_vif *wvif, struct ieee80211_tx_info *tx_info)
2964a5fb1bbSJérôme Pouiller {
2974a5fb1bbSJérôme Pouiller 	bool tx_policy_renew = false;
2984a5fb1bbSJérôme Pouiller 	u8 ret;
2994a5fb1bbSJérôme Pouiller 
3004a5fb1bbSJérôme Pouiller 	ret = wfx_tx_policy_get(wvif, tx_info->driver_rates, &tx_policy_renew);
3014a5fb1bbSJérôme Pouiller 	if (ret == HIF_TX_RETRY_POLICY_INVALID)
3024a5fb1bbSJérôme Pouiller 		dev_warn(wvif->wdev->dev, "unable to get a valid Tx policy");
3034a5fb1bbSJérôme Pouiller 
3044a5fb1bbSJérôme Pouiller 	if (tx_policy_renew) {
3054a5fb1bbSJérôme Pouiller 		wfx_tx_lock(wvif->wdev);
3064a5fb1bbSJérôme Pouiller 		if (!schedule_work(&wvif->tx_policy_upload_work))
3074a5fb1bbSJérôme Pouiller 			wfx_tx_unlock(wvif->wdev);
3084a5fb1bbSJérôme Pouiller 	}
3094a5fb1bbSJérôme Pouiller 	return ret;
3104a5fb1bbSJérôme Pouiller }
3114a5fb1bbSJérôme Pouiller 
wfx_tx_get_frame_format(struct ieee80211_tx_info * tx_info)3124a5fb1bbSJérôme Pouiller static int wfx_tx_get_frame_format(struct ieee80211_tx_info *tx_info)
3134a5fb1bbSJérôme Pouiller {
3144a5fb1bbSJérôme Pouiller 	if (!(tx_info->driver_rates[0].flags & IEEE80211_TX_RC_MCS))
3154a5fb1bbSJérôme Pouiller 		return HIF_FRAME_FORMAT_NON_HT;
3164a5fb1bbSJérôme Pouiller 	else if (!(tx_info->driver_rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD))
3174a5fb1bbSJérôme Pouiller 		return HIF_FRAME_FORMAT_MIXED_FORMAT_HT;
3184a5fb1bbSJérôme Pouiller 	else
3194a5fb1bbSJérôme Pouiller 		return HIF_FRAME_FORMAT_GF_HT_11N;
3204a5fb1bbSJérôme Pouiller }
3214a5fb1bbSJérôme Pouiller 
wfx_tx_get_icv_len(struct ieee80211_key_conf * hw_key)3224a5fb1bbSJérôme Pouiller static int wfx_tx_get_icv_len(struct ieee80211_key_conf *hw_key)
3234a5fb1bbSJérôme Pouiller {
3244a5fb1bbSJérôme Pouiller 	int mic_space;
3254a5fb1bbSJérôme Pouiller 
3264a5fb1bbSJérôme Pouiller 	if (!hw_key)
3274a5fb1bbSJérôme Pouiller 		return 0;
3284a5fb1bbSJérôme Pouiller 	if (hw_key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
3294a5fb1bbSJérôme Pouiller 		return 0;
3304a5fb1bbSJérôme Pouiller 	mic_space = (hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) ? 8 : 0;
3314a5fb1bbSJérôme Pouiller 	return hw_key->icv_len + mic_space;
3324a5fb1bbSJérôme Pouiller }
3334a5fb1bbSJérôme Pouiller 
wfx_tx_inner(struct wfx_vif * wvif,struct ieee80211_sta * sta,struct sk_buff * skb)3344a5fb1bbSJérôme Pouiller static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, struct sk_buff *skb)
3354a5fb1bbSJérôme Pouiller {
3364a5fb1bbSJérôme Pouiller 	struct wfx_hif_msg *hif_msg;
3374a5fb1bbSJérôme Pouiller 	struct wfx_hif_req_tx *req;
3384a5fb1bbSJérôme Pouiller 	struct wfx_tx_priv *tx_priv;
3394a5fb1bbSJérôme Pouiller 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
3404a5fb1bbSJérôme Pouiller 	struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
3414a5fb1bbSJérôme Pouiller 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3424a5fb1bbSJérôme Pouiller 	int queue_id = skb_get_queue_mapping(skb);
3434a5fb1bbSJérôme Pouiller 	size_t offset = (size_t)skb->data & 3;
3444a5fb1bbSJérôme Pouiller 	int wmsg_len = sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_req_tx) + offset;
3454a5fb1bbSJérôme Pouiller 
3464a5fb1bbSJérôme Pouiller 	WARN(queue_id >= IEEE80211_NUM_ACS, "unsupported queue_id");
3474a5fb1bbSJérôme Pouiller 	wfx_tx_fixup_rates(tx_info->driver_rates);
3484a5fb1bbSJérôme Pouiller 
3494a5fb1bbSJérôme Pouiller 	/* From now tx_info->control is unusable */
3504a5fb1bbSJérôme Pouiller 	memset(tx_info->rate_driver_data, 0, sizeof(struct wfx_tx_priv));
3514a5fb1bbSJérôme Pouiller 	/* Fill tx_priv */
3524a5fb1bbSJérôme Pouiller 	tx_priv = (struct wfx_tx_priv *)tx_info->rate_driver_data;
3534a5fb1bbSJérôme Pouiller 	tx_priv->icv_size = wfx_tx_get_icv_len(hw_key);
354f7385a20SJérôme Pouiller 	tx_priv->vif_id = wvif->id;
3554a5fb1bbSJérôme Pouiller 
3564a5fb1bbSJérôme Pouiller 	/* Fill hif_msg */
3574a5fb1bbSJérôme Pouiller 	WARN(skb_headroom(skb) < wmsg_len, "not enough space in skb");
3584a5fb1bbSJérôme Pouiller 	WARN(offset & 1, "attempt to transmit an unaligned frame");
3594a5fb1bbSJérôme Pouiller 	skb_put(skb, tx_priv->icv_size);
3604a5fb1bbSJérôme Pouiller 	skb_push(skb, wmsg_len);
3614a5fb1bbSJérôme Pouiller 	memset(skb->data, 0, wmsg_len);
3624a5fb1bbSJérôme Pouiller 	hif_msg = (struct wfx_hif_msg *)skb->data;
3634a5fb1bbSJérôme Pouiller 	hif_msg->len = cpu_to_le16(skb->len);
3644a5fb1bbSJérôme Pouiller 	hif_msg->id = HIF_REQ_ID_TX;
365f7385a20SJérôme Pouiller 	if (tx_info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
366f7385a20SJérôme Pouiller 		hif_msg->interface = 2;
367f7385a20SJérôme Pouiller 	else
3684a5fb1bbSJérôme Pouiller 		hif_msg->interface = wvif->id;
3694a5fb1bbSJérôme Pouiller 	if (skb->len > le16_to_cpu(wvif->wdev->hw_caps.size_inp_ch_buf)) {
3704a5fb1bbSJérôme Pouiller 		dev_warn(wvif->wdev->dev,
3714a5fb1bbSJérôme Pouiller 			 "requested frame size (%d) is larger than maximum supported (%d)\n",
3724a5fb1bbSJérôme Pouiller 			 skb->len, le16_to_cpu(wvif->wdev->hw_caps.size_inp_ch_buf));
3734a5fb1bbSJérôme Pouiller 		skb_pull(skb, wmsg_len);
3744a5fb1bbSJérôme Pouiller 		return -EIO;
3754a5fb1bbSJérôme Pouiller 	}
3764a5fb1bbSJérôme Pouiller 
3774a5fb1bbSJérôme Pouiller 	/* Fill tx request */
3784a5fb1bbSJérôme Pouiller 	req = (struct wfx_hif_req_tx *)hif_msg->body;
3794a5fb1bbSJérôme Pouiller 	/* packet_id just need to be unique on device. 32bits are more than necessary for that task,
3804a5fb1bbSJérôme Pouiller 	 * so we take advantage of it to add some extra data for debug.
3814a5fb1bbSJérôme Pouiller 	 */
3824a5fb1bbSJérôme Pouiller 	req->packet_id = atomic_add_return(1, &wvif->wdev->packet_id) & 0xFFFF;
3834a5fb1bbSJérôme Pouiller 	req->packet_id |= IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)) << 16;
3844a5fb1bbSJérôme Pouiller 	req->packet_id |= queue_id << 28;
3854a5fb1bbSJérôme Pouiller 
3864a5fb1bbSJérôme Pouiller 	req->fc_offset = offset;
3874a5fb1bbSJérôme Pouiller 	/* Queue index are inverted between firmware and Linux */
3884a5fb1bbSJérôme Pouiller 	req->queue_id = 3 - queue_id;
389f7385a20SJérôme Pouiller 	if (tx_info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
390f7385a20SJérôme Pouiller 		req->peer_sta_id = HIF_LINK_ID_NOT_ASSOCIATED;
391f7385a20SJérôme Pouiller 		req->retry_policy_index = HIF_TX_RETRY_POLICY_INVALID;
392f7385a20SJérôme Pouiller 		req->frame_format = HIF_FRAME_FORMAT_NON_HT;
393f7385a20SJérôme Pouiller 	} else {
3944a5fb1bbSJérôme Pouiller 		req->peer_sta_id = wfx_tx_get_link_id(wvif, sta, hdr);
3954a5fb1bbSJérôme Pouiller 		req->retry_policy_index = wfx_tx_get_retry_policy_id(wvif, tx_info);
3964a5fb1bbSJérôme Pouiller 		req->frame_format = wfx_tx_get_frame_format(tx_info);
397f7385a20SJérôme Pouiller 	}
3984a5fb1bbSJérôme Pouiller 	if (tx_info->driver_rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
3994a5fb1bbSJérôme Pouiller 		req->short_gi = 1;
4004a5fb1bbSJérôme Pouiller 	if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM)
4014a5fb1bbSJérôme Pouiller 		req->after_dtim = 1;
4024a5fb1bbSJérôme Pouiller 
4034a5fb1bbSJérôme Pouiller 	/* Auxiliary operations */
4044a5fb1bbSJérôme Pouiller 	wfx_tx_queues_put(wvif, skb);
4054a5fb1bbSJérôme Pouiller 	if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM)
4064a5fb1bbSJérôme Pouiller 		schedule_work(&wvif->update_tim_work);
4074a5fb1bbSJérôme Pouiller 	wfx_bh_request_tx(wvif->wdev);
4084a5fb1bbSJérôme Pouiller 	return 0;
4094a5fb1bbSJérôme Pouiller }
4104a5fb1bbSJérôme Pouiller 
wfx_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)4114a5fb1bbSJérôme Pouiller void wfx_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb)
4124a5fb1bbSJérôme Pouiller {
4134a5fb1bbSJérôme Pouiller 	struct wfx_dev *wdev = hw->priv;
4144a5fb1bbSJérôme Pouiller 	struct wfx_vif *wvif;
4154a5fb1bbSJérôme Pouiller 	struct ieee80211_sta *sta = control ? control->sta : NULL;
4164a5fb1bbSJérôme Pouiller 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4174a5fb1bbSJérôme Pouiller 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4184a5fb1bbSJérôme Pouiller 	size_t driver_data_room = sizeof_field(struct ieee80211_tx_info, rate_driver_data);
4194a5fb1bbSJérôme Pouiller 
4204a5fb1bbSJérôme Pouiller 	BUILD_BUG_ON_MSG(sizeof(struct wfx_tx_priv) > driver_data_room,
4214a5fb1bbSJérôme Pouiller 			 "struct tx_priv is too large");
4224a5fb1bbSJérôme Pouiller 	WARN(skb->next || skb->prev, "skb is already member of a list");
4234a5fb1bbSJérôme Pouiller 	/* control.vif can be NULL for injected frames */
4244a5fb1bbSJérôme Pouiller 	if (tx_info->control.vif)
4254a5fb1bbSJérôme Pouiller 		wvif = (struct wfx_vif *)tx_info->control.vif->drv_priv;
4264a5fb1bbSJérôme Pouiller 	else
4274a5fb1bbSJérôme Pouiller 		wvif = wvif_iterate(wdev, NULL);
4284a5fb1bbSJérôme Pouiller 	if (WARN_ON(!wvif))
4294a5fb1bbSJérôme Pouiller 		goto drop;
4304a5fb1bbSJérôme Pouiller 	/* Because of TX_AMPDU_SETUP_IN_HW, mac80211 does not try to send any BlockAck session
4314a5fb1bbSJérôme Pouiller 	 * management frame. The check below exist just in case.
4324a5fb1bbSJérôme Pouiller 	 */
4334a5fb1bbSJérôme Pouiller 	if (wfx_is_action_back(hdr)) {
4344a5fb1bbSJérôme Pouiller 		dev_info(wdev->dev, "drop BA action\n");
4354a5fb1bbSJérôme Pouiller 		goto drop;
4364a5fb1bbSJérôme Pouiller 	}
4374a5fb1bbSJérôme Pouiller 	if (wfx_tx_inner(wvif, sta, skb))
4384a5fb1bbSJérôme Pouiller 		goto drop;
4394a5fb1bbSJérôme Pouiller 
4404a5fb1bbSJérôme Pouiller 	return;
4414a5fb1bbSJérôme Pouiller 
4424a5fb1bbSJérôme Pouiller drop:
4434a5fb1bbSJérôme Pouiller 	ieee80211_tx_status_irqsafe(wdev->hw, skb);
4444a5fb1bbSJérôme Pouiller }
4454a5fb1bbSJérôme Pouiller 
wfx_skb_dtor(struct wfx_vif * wvif,struct sk_buff * skb)4464a5fb1bbSJérôme Pouiller static void wfx_skb_dtor(struct wfx_vif *wvif, struct sk_buff *skb)
4474a5fb1bbSJérôme Pouiller {
4484a5fb1bbSJérôme Pouiller 	struct wfx_hif_msg *hif = (struct wfx_hif_msg *)skb->data;
4494a5fb1bbSJérôme Pouiller 	struct wfx_hif_req_tx *req = (struct wfx_hif_req_tx *)hif->body;
4504a5fb1bbSJérôme Pouiller 	unsigned int offset = sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_req_tx) +
4514a5fb1bbSJérôme Pouiller 			      req->fc_offset;
4524a5fb1bbSJérôme Pouiller 
4534a5fb1bbSJérôme Pouiller 	if (!wvif) {
4544a5fb1bbSJérôme Pouiller 		pr_warn("vif associated with the skb does not exist anymore\n");
4554a5fb1bbSJérôme Pouiller 		return;
4564a5fb1bbSJérôme Pouiller 	}
4574a5fb1bbSJérôme Pouiller 	wfx_tx_policy_put(wvif, req->retry_policy_index);
4584a5fb1bbSJérôme Pouiller 	skb_pull(skb, offset);
4594a5fb1bbSJérôme Pouiller 	ieee80211_tx_status_irqsafe(wvif->wdev->hw, skb);
4604a5fb1bbSJérôme Pouiller }
4614a5fb1bbSJérôme Pouiller 
wfx_tx_fill_rates(struct wfx_dev * wdev,struct ieee80211_tx_info * tx_info,const struct wfx_hif_cnf_tx * arg)4624a5fb1bbSJérôme Pouiller static void wfx_tx_fill_rates(struct wfx_dev *wdev, struct ieee80211_tx_info *tx_info,
4634a5fb1bbSJérôme Pouiller 			      const struct wfx_hif_cnf_tx *arg)
4644a5fb1bbSJérôme Pouiller {
4654a5fb1bbSJérôme Pouiller 	struct ieee80211_tx_rate *rate;
4664a5fb1bbSJérôme Pouiller 	int tx_count;
4674a5fb1bbSJérôme Pouiller 	int i;
4684a5fb1bbSJérôme Pouiller 
4694a5fb1bbSJérôme Pouiller 	tx_count = arg->ack_failures;
4704a5fb1bbSJérôme Pouiller 	if (!arg->status || arg->ack_failures)
4714a5fb1bbSJérôme Pouiller 		tx_count += 1; /* Also report success */
4724a5fb1bbSJérôme Pouiller 	for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
4734a5fb1bbSJérôme Pouiller 		rate = &tx_info->status.rates[i];
4744a5fb1bbSJérôme Pouiller 		if (rate->idx < 0)
4754a5fb1bbSJérôme Pouiller 			break;
4764a5fb1bbSJérôme Pouiller 		if (tx_count < rate->count && arg->status == HIF_STATUS_TX_FAIL_RETRIES &&
4774a5fb1bbSJérôme Pouiller 		    arg->ack_failures)
4784a5fb1bbSJérôme Pouiller 			dev_dbg(wdev->dev, "all retries were not consumed: %d != %d\n",
4794a5fb1bbSJérôme Pouiller 				rate->count, tx_count);
4804a5fb1bbSJérôme Pouiller 		if (tx_count <= rate->count && tx_count &&
4814a5fb1bbSJérôme Pouiller 		    arg->txed_rate != wfx_get_hw_rate(wdev, rate))
4824a5fb1bbSJérôme Pouiller 			dev_dbg(wdev->dev, "inconsistent tx_info rates: %d != %d\n",
4834a5fb1bbSJérôme Pouiller 				arg->txed_rate, wfx_get_hw_rate(wdev, rate));
4844a5fb1bbSJérôme Pouiller 		if (tx_count > rate->count) {
4854a5fb1bbSJérôme Pouiller 			tx_count -= rate->count;
4864a5fb1bbSJérôme Pouiller 		} else if (!tx_count) {
4874a5fb1bbSJérôme Pouiller 			rate->count = 0;
4884a5fb1bbSJérôme Pouiller 			rate->idx = -1;
4894a5fb1bbSJérôme Pouiller 		} else {
4904a5fb1bbSJérôme Pouiller 			rate->count = tx_count;
4914a5fb1bbSJérôme Pouiller 			tx_count = 0;
4924a5fb1bbSJérôme Pouiller 		}
4934a5fb1bbSJérôme Pouiller 	}
4944a5fb1bbSJérôme Pouiller 	if (tx_count)
4954a5fb1bbSJérôme Pouiller 		dev_dbg(wdev->dev, "%d more retries than expected\n", tx_count);
4964a5fb1bbSJérôme Pouiller }
4974a5fb1bbSJérôme Pouiller 
wfx_tx_confirm_cb(struct wfx_dev * wdev,const struct wfx_hif_cnf_tx * arg)4984a5fb1bbSJérôme Pouiller void wfx_tx_confirm_cb(struct wfx_dev *wdev, const struct wfx_hif_cnf_tx *arg)
4994a5fb1bbSJérôme Pouiller {
5004a5fb1bbSJérôme Pouiller 	const struct wfx_tx_priv *tx_priv;
5014a5fb1bbSJérôme Pouiller 	struct ieee80211_tx_info *tx_info;
5024a5fb1bbSJérôme Pouiller 	struct wfx_vif *wvif;
5034a5fb1bbSJérôme Pouiller 	struct sk_buff *skb;
5044a5fb1bbSJérôme Pouiller 
5054a5fb1bbSJérôme Pouiller 	skb = wfx_pending_get(wdev, arg->packet_id);
5064a5fb1bbSJérôme Pouiller 	if (!skb) {
5074a5fb1bbSJérôme Pouiller 		dev_warn(wdev->dev, "received unknown packet_id (%#.8x) from chip\n",
5084a5fb1bbSJérôme Pouiller 			 arg->packet_id);
5094a5fb1bbSJérôme Pouiller 		return;
5104a5fb1bbSJérôme Pouiller 	}
5114a5fb1bbSJérôme Pouiller 	tx_info = IEEE80211_SKB_CB(skb);
5124a5fb1bbSJérôme Pouiller 	tx_priv = wfx_skb_tx_priv(skb);
513f7385a20SJérôme Pouiller 	wvif = wfx_skb_wvif(wdev, skb);
5144a5fb1bbSJérôme Pouiller 	WARN_ON(!wvif);
5154a5fb1bbSJérôme Pouiller 	if (!wvif)
5164a5fb1bbSJérôme Pouiller 		return;
5174a5fb1bbSJérôme Pouiller 
5184a5fb1bbSJérôme Pouiller 	/* Note that wfx_pending_get_pkt_us_delay() get data from tx_info */
5194a5fb1bbSJérôme Pouiller 	_trace_tx_stats(arg, skb, wfx_pending_get_pkt_us_delay(wdev, skb));
5204a5fb1bbSJérôme Pouiller 	wfx_tx_fill_rates(wdev, tx_info, arg);
5214a5fb1bbSJérôme Pouiller 	skb_trim(skb, skb->len - tx_priv->icv_size);
5224a5fb1bbSJérôme Pouiller 
5234a5fb1bbSJérôme Pouiller 	/* From now, you can touch to tx_info->status, but do not touch to tx_priv anymore */
5244a5fb1bbSJérôme Pouiller 	/* FIXME: use ieee80211_tx_info_clear_status() */
5254a5fb1bbSJérôme Pouiller 	memset(tx_info->rate_driver_data, 0, sizeof(tx_info->rate_driver_data));
5264a5fb1bbSJérôme Pouiller 	memset(tx_info->pad, 0, sizeof(tx_info->pad));
5274a5fb1bbSJérôme Pouiller 
5284a5fb1bbSJérôme Pouiller 	if (!arg->status) {
5294a5fb1bbSJérôme Pouiller 		tx_info->status.tx_time = le32_to_cpu(arg->media_delay) -
5304a5fb1bbSJérôme Pouiller 					  le32_to_cpu(arg->tx_queue_delay);
5314a5fb1bbSJérôme Pouiller 		if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
5324a5fb1bbSJérôme Pouiller 			tx_info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
5334a5fb1bbSJérôme Pouiller 		else
5344a5fb1bbSJérôme Pouiller 			tx_info->flags |= IEEE80211_TX_STAT_ACK;
5354a5fb1bbSJérôme Pouiller 	} else if (arg->status == HIF_STATUS_TX_FAIL_REQUEUE) {
5364a5fb1bbSJérôme Pouiller 		WARN(!arg->requeue, "incoherent status and result_flags");
5374a5fb1bbSJérôme Pouiller 		if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
5384a5fb1bbSJérôme Pouiller 			wvif->after_dtim_tx_allowed = false; /* DTIM period elapsed */
5394a5fb1bbSJérôme Pouiller 			schedule_work(&wvif->update_tim_work);
5404a5fb1bbSJérôme Pouiller 		}
5414a5fb1bbSJérôme Pouiller 		tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
5424a5fb1bbSJérôme Pouiller 	}
5434a5fb1bbSJérôme Pouiller 	wfx_skb_dtor(wvif, skb);
5444a5fb1bbSJérôme Pouiller }
5454a5fb1bbSJérôme Pouiller 
wfx_flush_vif(struct wfx_vif * wvif,u32 queues,struct sk_buff_head * dropped)5464a5fb1bbSJérôme Pouiller static void wfx_flush_vif(struct wfx_vif *wvif, u32 queues, struct sk_buff_head *dropped)
5474a5fb1bbSJérôme Pouiller {
5484a5fb1bbSJérôme Pouiller 	struct wfx_queue *queue;
5494a5fb1bbSJérôme Pouiller 	int i;
5504a5fb1bbSJérôme Pouiller 
5514a5fb1bbSJérôme Pouiller 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
5524a5fb1bbSJérôme Pouiller 		if (!(BIT(i) & queues))
5534a5fb1bbSJérôme Pouiller 			continue;
5544a5fb1bbSJérôme Pouiller 		queue = &wvif->tx_queue[i];
5554a5fb1bbSJérôme Pouiller 		if (dropped)
5564a5fb1bbSJérôme Pouiller 			wfx_tx_queue_drop(wvif, queue, dropped);
5574a5fb1bbSJérôme Pouiller 	}
5584a5fb1bbSJérôme Pouiller 	if (wvif->wdev->chip_frozen)
5594a5fb1bbSJérôme Pouiller 		return;
5604a5fb1bbSJérôme Pouiller 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
5614a5fb1bbSJérôme Pouiller 		if (!(BIT(i) & queues))
5624a5fb1bbSJérôme Pouiller 			continue;
5634a5fb1bbSJérôme Pouiller 		queue = &wvif->tx_queue[i];
5644a5fb1bbSJérôme Pouiller 		if (wait_event_timeout(wvif->wdev->tx_dequeue, wfx_tx_queue_empty(wvif, queue),
5654a5fb1bbSJérôme Pouiller 				       msecs_to_jiffies(1000)) <= 0)
5664a5fb1bbSJérôme Pouiller 			dev_warn(wvif->wdev->dev, "frames queued while flushing tx queues?");
5674a5fb1bbSJérôme Pouiller 	}
5684a5fb1bbSJérôme Pouiller }
5694a5fb1bbSJérôme Pouiller 
wfx_flush(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 queues,bool drop)5704a5fb1bbSJérôme Pouiller void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u32 queues, bool drop)
5714a5fb1bbSJérôme Pouiller {
5724a5fb1bbSJérôme Pouiller 	struct wfx_dev *wdev = hw->priv;
5734a5fb1bbSJérôme Pouiller 	struct sk_buff_head dropped;
5744a5fb1bbSJérôme Pouiller 	struct wfx_vif *wvif;
5754a5fb1bbSJérôme Pouiller 	struct sk_buff *skb;
5764a5fb1bbSJérôme Pouiller 
5774a5fb1bbSJérôme Pouiller 	skb_queue_head_init(&dropped);
5784a5fb1bbSJérôme Pouiller 	if (vif) {
5794a5fb1bbSJérôme Pouiller 		wvif = (struct wfx_vif *)vif->drv_priv;
5804a5fb1bbSJérôme Pouiller 		wfx_flush_vif(wvif, queues, drop ? &dropped : NULL);
5814a5fb1bbSJérôme Pouiller 	} else {
5824a5fb1bbSJérôme Pouiller 		wvif = NULL;
5834a5fb1bbSJérôme Pouiller 		while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
5844a5fb1bbSJérôme Pouiller 			wfx_flush_vif(wvif, queues, drop ? &dropped : NULL);
5854a5fb1bbSJérôme Pouiller 	}
5864a5fb1bbSJérôme Pouiller 	wfx_tx_flush(wdev);
5874a5fb1bbSJérôme Pouiller 	if (wdev->chip_frozen)
5884a5fb1bbSJérôme Pouiller 		wfx_pending_drop(wdev, &dropped);
5894a5fb1bbSJérôme Pouiller 	while ((skb = skb_dequeue(&dropped)) != NULL) {
590f7385a20SJérôme Pouiller 		wvif = wfx_skb_wvif(wdev, skb);
5914a5fb1bbSJérôme Pouiller 		ieee80211_tx_info_clear_status(IEEE80211_SKB_CB(skb));
5924a5fb1bbSJérôme Pouiller 		wfx_skb_dtor(wvif, skb);
5934a5fb1bbSJérôme Pouiller 	}
5944a5fb1bbSJérôme Pouiller }
595