data_tx.c 17 KB

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