developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 1 | From 077abb918aa653fa04d5e0acb08c31619a42e329 Mon Sep 17 00:00:00 2001 |
developer | 68e1eb2 | 2022-05-09 17:02:12 +0800 | [diff] [blame] | 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 3 | Date: Mon, 16 May 2022 10:03:36 +0800 |
| 4 | Subject: [PATCH 3/5] mt76: mt7915: drop packets when TWT stations use more |
| 5 | tokens than 128 |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 6 | |
| 7 | --- |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 8 | .../net/wireless/mediatek/mt76/mt7915/mac.c | 21 ++++++++++++++++--- |
| 9 | .../wireless/mediatek/mt76/mt7915/mt7915.h | 2 ++ |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 10 | 2 files changed, 20 insertions(+), 3 deletions(-) |
| 11 | |
| 12 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 13 | index 12afb204..d80ef1b3 100644 |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 14 | --- a/mt7915/mac.c |
| 15 | +++ b/mt7915/mac.c |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 16 | @@ -1315,6 +1315,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 17 | 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; |
| 21 | struct mt76_txwi_cache *t; |
| 22 | struct mt7915_txp *txp; |
| 23 | int id, i, nbuf = tx_info->nbuf - 1; |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 24 | @@ -1328,8 +1329,6 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 25 | 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)) { |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 33 | @@ -1345,10 +1344,22 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 34 | mgmt->u.action.category == 0xff) |
| 35 | return -1; |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 36 | |
| 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); |
| 54 | mt7915_mac_write_txwi(dev, txwi_ptr, tx_info->skb, wcid, pid, key, |
| 55 | false); |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 56 | @@ -1540,6 +1551,7 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len) |
developer | beb7437 | 2022-05-06 16:53:33 +0800 | [diff] [blame] | 57 | struct mt76_dev *mdev = &dev->mt76; |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 58 | struct mt76_txwi_cache *txwi; |
| 59 | struct ieee80211_sta *sta = NULL; |
developer | 68e1eb2 | 2022-05-09 17:02:12 +0800 | [diff] [blame] | 60 | + struct mt7915_sta *msta = NULL; |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 61 | LIST_HEAD(free_list); |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 62 | void *end = data + len; |
developer | beb7437 | 2022-05-06 16:53:33 +0800 | [diff] [blame] | 63 | bool v3, wake = false; |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 64 | @@ -1563,7 +1575,6 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len) |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 65 | * 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 | |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 72 | @@ -1596,6 +1607,10 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len) |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 73 | 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 | } |
| 83 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 84 | index 4b375629..6508cc26 100644 |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 85 | --- a/mt7915/mt7915.h |
| 86 | +++ b/mt7915/mt7915.h |
| 87 | @@ -136,6 +136,8 @@ struct mt7915_sta { |
| 88 | 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 | -- |
developer | 4c6b600 | 2022-05-30 16:36:44 +0800 | [diff] [blame] | 97 | 2.25.1 |
developer | 7bfba5a | 2022-05-03 10:24:17 +0800 | [diff] [blame] | 98 | |