blob: e077acf390903137f17e6b981eb27f5e4f5b3d2b [file] [log] [blame]
developer4721e252022-06-21 16:41:28 +08001From 23de5ffe66f73e5fbd22a441f7ca1f612f1bd158 Mon Sep 17 00:00:00 2001
developer68e1eb22022-05-09 17:02:12 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
developerf64861f2022-06-22 11:44:53 +08003Date: Wed, 22 Jun 2022 10:58:37 +0800
developerbd398d52022-06-06 20:53:24 +08004Subject: [PATCH 1113/1115] mt76: mt7915: drop packets when TWT stations use
5 more tokens than 128
developer7bfba5a2022-05-03 10:24:17 +08006
7---
developer4721e252022-06-21 16:41:28 +08008 mt7915/mac.c | 21 ++++++++++++++++++---
9 mt7915/mt7915.h | 2 ++
developer7bfba5a2022-05-03 10:24:17 +080010 2 files changed, 20 insertions(+), 3 deletions(-)
11
12diff --git a/mt7915/mac.c b/mt7915/mac.c
developer4721e252022-06-21 16:41:28 +080013index 8fd4618..fd0dd50 100644
developer7bfba5a2022-05-03 10:24:17 +080014--- a/mt7915/mac.c
15+++ b/mt7915/mac.c
developerf64861f2022-06-22 11:44:53 +080016@@ -724,6 +724,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer7bfba5a2022-05-03 10:24:17 +080017 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb);
18 struct ieee80211_key_conf *key = info->control.hw_key;
19 struct ieee80211_vif *vif = info->control.vif;
20+ struct mt7915_sta *msta = NULL;
developerf64861f2022-06-22 11:44:53 +080021 struct mt76_connac_fw_txp *txp;
developer7bfba5a2022-05-03 10:24:17 +080022 struct mt76_txwi_cache *t;
developer7bfba5a2022-05-03 10:24:17 +080023 int id, i, nbuf = tx_info->nbuf - 1;
developerf64861f2022-06-22 11:44:53 +080024@@ -737,8 +738,6 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer7bfba5a2022-05-03 10:24:17 +080025 wcid = &dev->mt76.global_wcid;
26
27 if (sta) {
28- struct mt7915_sta *msta;
29-
30 msta = (struct mt7915_sta *)sta->drv_priv;
31
32 if (time_after(jiffies, msta->jiffies + HZ / 4)) {
developerf64861f2022-06-22 11:44:53 +080033@@ -754,10 +753,22 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer4c6b6002022-05-30 16:36:44 +080034 mgmt->u.action.category == 0xff)
35 return -1;
developer7bfba5a2022-05-03 10:24:17 +080036
37+ spin_lock_bh(&mdev->token_lock);
38+ if (msta && msta->twt.flowid_mask && msta->token_count > 128) {
39+ spin_unlock_bh(&mdev->token_lock);
40+ return -1;
41+ }
42+ spin_unlock_bh(&mdev->token_lock);
43+
44 id = mt76_token_consume(mdev, &t);
45 if (id < 0)
46 return id;
47
48+ spin_lock_bh(&mdev->token_lock);
49+ if (msta)
50+ msta->token_count++;
51+ spin_unlock_bh(&mdev->token_lock);
52+
53 pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb);
developerf64861f2022-06-22 11:44:53 +080054 mt7915_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, pid, key, 0);
developerbd398d52022-06-06 20:53:24 +080055
developerf64861f2022-06-22 11:44:53 +080056@@ -937,6 +948,7 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
developerbeb74372022-05-06 16:53:33 +080057 struct mt76_dev *mdev = &dev->mt76;
developer7bfba5a2022-05-03 10:24:17 +080058 struct mt76_txwi_cache *txwi;
59 struct ieee80211_sta *sta = NULL;
developer68e1eb22022-05-09 17:02:12 +080060+ struct mt7915_sta *msta = NULL;
developer7bfba5a2022-05-03 10:24:17 +080061 LIST_HEAD(free_list);
developer7bfba5a2022-05-03 10:24:17 +080062 void *end = data + len;
developerbeb74372022-05-06 16:53:33 +080063 bool v3, wake = false;
developerf64861f2022-06-22 11:44:53 +080064@@ -960,7 +972,6 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
developer7bfba5a2022-05-03 10:24:17 +080065 * 1'b0: msdu_id with the same 'wcid pair' as above.
66 */
67 if (info & MT_TX_FREE_PAIR) {
68- struct mt7915_sta *msta;
69 struct mt76_wcid *wcid;
70 u16 idx;
71
developerf64861f2022-06-22 11:44:53 +080072@@ -993,6 +1004,10 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
developer7bfba5a2022-05-03 10:24:17 +080073 txwi = mt76_token_release(mdev, msdu, &wake);
74 if (!txwi)
75 continue;
76+ spin_lock(&mdev->token_lock);
77+ if (msta)
78+ msta->token_count--;
79+ spin_unlock(&mdev->token_lock);
80
81 mt7915_txwi_free(dev, txwi, sta, &free_list);
82 }
83diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer4721e252022-06-21 16:41:28 +080084index ff92e55..6235014 100644
developer7bfba5a2022-05-03 10:24:17 +080085--- a/mt7915/mt7915.h
86+++ b/mt7915/mt7915.h
developerf64861f2022-06-22 11:44:53 +080087@@ -136,6 +136,8 @@ struct mt7915_sta {
developer7bfba5a2022-05-03 10:24:17 +080088 u8 flowid_mask;
89 struct mt7915_twt_flow flow[MT7915_MAX_STA_TWT_AGRT];
90 } twt;
91+
92+ int token_count;
93 };
94
95 struct mt7915_vif_cap {
96--
developer4721e252022-06-21 16:41:28 +0800972.18.0
developer7bfba5a2022-05-03 10:24:17 +080098