blob: bb06dffd2a6f69d0238e756a643e1393feaaf8aa [file] [log] [blame]
developerb7c46752022-07-04 19:51:38 +08001From 9bc707077df60aa6423c89b1d17fd8a5f4e2d36b Mon Sep 17 00:00:00 2001
2From: Bo Jiao <Bo.Jiao@mediatek.com>
3Date: Mon, 4 Jul 2022 19:24:34 +0800
4Subject: [PATCH] mt76: mt7915: drop packets when TWT stations use
developer7bfba5a2022-05-03 10:24:17 +08005
6---
developer4721e252022-06-21 16:41:28 +08007 mt7915/mac.c | 21 ++++++++++++++++++---
8 mt7915/mt7915.h | 2 ++
developer7bfba5a2022-05-03 10:24:17 +08009 2 files changed, 20 insertions(+), 3 deletions(-)
developerb7c46752022-07-04 19:51:38 +080010 mode change 100644 => 100755 mt7915/mac.c
developer7bfba5a2022-05-03 10:24:17 +080011
12diff --git a/mt7915/mac.c b/mt7915/mac.c
developerb7c46752022-07-04 19:51:38 +080013old mode 100644
14new mode 100755
15index 5e5df23d..55b38d16
developer7bfba5a2022-05-03 10:24:17 +080016--- a/mt7915/mac.c
17+++ b/mt7915/mac.c
developerb7c46752022-07-04 19:51:38 +080018@@ -725,6 +725,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer7bfba5a2022-05-03 10:24:17 +080019 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb);
20 struct ieee80211_key_conf *key = info->control.hw_key;
21 struct ieee80211_vif *vif = info->control.vif;
22+ struct mt7915_sta *msta = NULL;
developerf64861f2022-06-22 11:44:53 +080023 struct mt76_connac_fw_txp *txp;
developer7bfba5a2022-05-03 10:24:17 +080024 struct mt76_txwi_cache *t;
developer7bfba5a2022-05-03 10:24:17 +080025 int id, i, nbuf = tx_info->nbuf - 1;
developerb7c46752022-07-04 19:51:38 +080026@@ -738,8 +739,6 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer7bfba5a2022-05-03 10:24:17 +080027 wcid = &dev->mt76.global_wcid;
28
29 if (sta) {
30- struct mt7915_sta *msta;
31-
32 msta = (struct mt7915_sta *)sta->drv_priv;
33
34 if (time_after(jiffies, msta->jiffies + HZ / 4)) {
developerb7c46752022-07-04 19:51:38 +080035@@ -755,10 +754,22 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer4c6b6002022-05-30 16:36:44 +080036 mgmt->u.action.category == 0xff)
37 return -1;
developer7bfba5a2022-05-03 10:24:17 +080038
39+ spin_lock_bh(&mdev->token_lock);
40+ if (msta && msta->twt.flowid_mask && msta->token_count > 128) {
41+ spin_unlock_bh(&mdev->token_lock);
42+ return -1;
43+ }
44+ spin_unlock_bh(&mdev->token_lock);
45+
46 id = mt76_token_consume(mdev, &t);
47 if (id < 0)
48 return id;
49
50+ spin_lock_bh(&mdev->token_lock);
51+ if (msta)
52+ msta->token_count++;
53+ spin_unlock_bh(&mdev->token_lock);
54+
55 pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb);
developerb7c46752022-07-04 19:51:38 +080056 mt7915_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, pid, key,
57 qid, 0);
58@@ -939,6 +950,7 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
developerbeb74372022-05-06 16:53:33 +080059 struct mt76_dev *mdev = &dev->mt76;
developer7bfba5a2022-05-03 10:24:17 +080060 struct mt76_txwi_cache *txwi;
61 struct ieee80211_sta *sta = NULL;
developer68e1eb22022-05-09 17:02:12 +080062+ struct mt7915_sta *msta = NULL;
developer7bfba5a2022-05-03 10:24:17 +080063 LIST_HEAD(free_list);
developer7bfba5a2022-05-03 10:24:17 +080064 void *end = data + len;
developerbeb74372022-05-06 16:53:33 +080065 bool v3, wake = false;
developerb7c46752022-07-04 19:51:38 +080066@@ -962,7 +974,6 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
developer7bfba5a2022-05-03 10:24:17 +080067 * 1'b0: msdu_id with the same 'wcid pair' as above.
68 */
69 if (info & MT_TX_FREE_PAIR) {
70- struct mt7915_sta *msta;
71 struct mt76_wcid *wcid;
72 u16 idx;
73
developerb7c46752022-07-04 19:51:38 +080074@@ -995,6 +1006,10 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
developer7bfba5a2022-05-03 10:24:17 +080075 txwi = mt76_token_release(mdev, msdu, &wake);
76 if (!txwi)
77 continue;
78+ spin_lock(&mdev->token_lock);
79+ if (msta)
80+ msta->token_count--;
81+ spin_unlock(&mdev->token_lock);
82
83 mt7915_txwi_free(dev, txwi, sta, &free_list);
84 }
85diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerb7c46752022-07-04 19:51:38 +080086index 7c7d6bd3..5f11b3fb 100644
developer7bfba5a2022-05-03 10:24:17 +080087--- a/mt7915/mt7915.h
88+++ b/mt7915/mt7915.h
developerf64861f2022-06-22 11:44:53 +080089@@ -136,6 +136,8 @@ struct mt7915_sta {
developer7bfba5a2022-05-03 10:24:17 +080090 u8 flowid_mask;
91 struct mt7915_twt_flow flow[MT7915_MAX_STA_TWT_AGRT];
92 } twt;
93+
94+ int token_count;
95 };
96
97 struct mt7915_vif_cap {
98--
developer4721e252022-06-21 16:41:28 +0800992.18.0
developer7bfba5a2022-05-03 10:24:17 +0800100