developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From 08bab29bc70a7b21150167f2ae502d8e5538c743 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 3 | Date: Tue, 30 Jul 2024 19:49:39 +0800 |
| 4 | Subject: [PATCH 190/199] mtk: mt76: mt7996: add per-band token limit |
| 5 | |
| 6 | Add a threshold for per-band token count. |
| 7 | The bands use the same token pool so a band cannot transmit if |
| 8 | the other band occupy too many tokens. With this patch, we can |
| 9 | prevent a band from interfering with the other band. |
| 10 | |
| 11 | Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 12 | --- |
| 13 | mt76.h | 6 +++++- |
| 14 | mt7996/init.c | 2 ++ |
| 15 | mt7996/mac.c | 5 ++++- |
| 16 | mt7996/mt7996.h | 1 + |
| 17 | mt7996/mtk_debugfs.c | 14 ++++++++++++-- |
| 18 | tx.c | 19 ++++++++++++++++--- |
| 19 | 6 files changed, 40 insertions(+), 7 deletions(-) |
| 20 | |
| 21 | diff --git a/mt76.h b/mt76.h |
| 22 | index 1858f542..e5e5529d 100644 |
| 23 | --- a/mt76.h |
| 24 | +++ b/mt76.h |
| 25 | @@ -462,6 +462,7 @@ struct mt76_txwi_cache { |
| 26 | dma_addr_t dma_addr; |
| 27 | |
| 28 | unsigned long jiffies; |
| 29 | + u8 phy_idx; |
| 30 | |
| 31 | struct sk_buff *skb; |
| 32 | }; |
| 33 | @@ -960,6 +961,7 @@ struct mt76_phy { |
| 34 | } leds; |
| 35 | struct mt76_tx_debug tx_dbg_stats; |
| 36 | struct mt76_rx_debug rx_dbg_stats; |
| 37 | + int tokens; |
| 38 | }; |
| 39 | |
| 40 | struct mt76_dev { |
| 41 | @@ -1009,6 +1011,7 @@ struct mt76_dev { |
| 42 | u16 wed_token_count; |
| 43 | u16 token_count; |
| 44 | u16 token_size; |
| 45 | + u16 token_threshold; |
| 46 | |
| 47 | spinlock_t rx_token_lock; |
| 48 | struct idr rx_token; |
| 49 | @@ -1879,7 +1882,8 @@ static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q) |
| 50 | |
| 51 | struct mt76_txwi_cache * |
| 52 | mt76_token_release(struct mt76_dev *dev, int token, bool *wake); |
| 53 | -int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi); |
| 54 | +int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi, |
| 55 | + u8 phy_idx); |
| 56 | void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); |
| 57 | struct mt76_rxwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); |
| 58 | int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| 59 | diff --git a/mt7996/init.c b/mt7996/init.c |
| 60 | index 2f43c0ff..bad4b1b7 100644 |
| 61 | --- a/mt7996/init.c |
| 62 | +++ b/mt7996/init.c |
| 63 | @@ -1770,6 +1770,8 @@ int mt7996_register_device(struct mt7996_dev *dev) |
| 64 | if (ret) |
| 65 | return ret; |
| 66 | |
| 67 | + dev->mt76.token_threshold = MT7996_PER_BAND_TOKEN_SIZE; |
| 68 | + |
| 69 | ret = mt7996_init_dev_debugfs(&dev->phy); |
| 70 | if (ret) |
| 71 | goto error; |
| 72 | diff --git a/mt7996/mac.c b/mt7996/mac.c |
| 73 | index 32f5b859..f9344f28 100644 |
| 74 | --- a/mt7996/mac.c |
| 75 | +++ b/mt7996/mac.c |
| 76 | @@ -959,7 +959,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 77 | t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); |
| 78 | t->skb = tx_info->skb; |
| 79 | |
| 80 | - id = mt76_token_consume(mdev, &t); |
| 81 | + id = mt76_token_consume(mdev, &t, mconf->mt76.band_idx); |
| 82 | if (id < 0) { |
| 83 | mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_GET_TOKEN_FAIL]++; |
| 84 | return id; |
| 85 | @@ -1683,8 +1683,11 @@ void mt7996_tx_token_put(struct mt7996_dev *dev) |
| 86 | |
| 87 | spin_lock_bh(&dev->mt76.token_lock); |
| 88 | idr_for_each_entry(&dev->mt76.token, txwi, id) { |
| 89 | + struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, txwi->phy_idx); |
| 90 | + |
| 91 | mt7996_txwi_free(dev, txwi, NULL, NULL, NULL); |
| 92 | dev->mt76.token_count--; |
| 93 | + phy->tokens--; |
| 94 | } |
| 95 | spin_unlock_bh(&dev->mt76.token_lock); |
| 96 | idr_destroy(&dev->mt76.token); |
| 97 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| 98 | index fa884316..04832b0c 100644 |
| 99 | --- a/mt7996/mt7996.h |
| 100 | +++ b/mt7996/mt7996.h |
| 101 | @@ -76,6 +76,7 @@ |
| 102 | #define MT7996_TOKEN_SIZE 16384 |
| 103 | #define MT7996_HW_TOKEN_SIZE 8192 |
| 104 | #define MT7996_SW_TOKEN_SIZE 15360 |
| 105 | +#define MT7996_PER_BAND_TOKEN_SIZE 5120 |
| 106 | |
| 107 | #define MT7996_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ |
| 108 | #define MT7996_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ |
| 109 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
| 110 | index fa8de2db..a4703b07 100644 |
| 111 | --- a/mt7996/mtk_debugfs.c |
| 112 | +++ b/mt7996/mtk_debugfs.c |
| 113 | @@ -2401,7 +2401,7 @@ static int mt7996_sta_info(struct seq_file *s, void *data) |
| 114 | static int mt7996_token_read(struct seq_file *s, void *data) |
| 115 | { |
| 116 | struct mt7996_dev *dev = dev_get_drvdata(s->private); |
| 117 | - int msdu_id; |
| 118 | + int msdu_id, i; |
| 119 | struct mt76_txwi_cache *txwi; |
| 120 | |
| 121 | seq_printf(s, "Token from host:\n"); |
| 122 | @@ -2410,8 +2410,18 @@ static int mt7996_token_read(struct seq_file *s, void *data) |
| 123 | seq_printf(s, "%4d (pending time %u ms)\n", msdu_id, |
| 124 | jiffies_to_msecs(jiffies - txwi->jiffies)); |
| 125 | } |
| 126 | - spin_unlock_bh(&dev->mt76.token_lock); |
| 127 | seq_printf(s, "\n"); |
| 128 | + for (i = 0; i < __MT_MAX_BAND; i++) { |
| 129 | + struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, i); |
| 130 | + |
| 131 | + if (!mt7996_band_valid(dev, i)) |
| 132 | + continue; |
| 133 | + |
| 134 | + seq_printf(s, "Band%u consume: %d, free: %d total: %d\n", |
| 135 | + i, phy->tokens, dev->mt76.token_threshold - phy->tokens, |
| 136 | + dev->mt76.token_threshold); |
| 137 | + } |
| 138 | + spin_unlock_bh(&dev->mt76.token_lock); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | diff --git a/tx.c b/tx.c |
| 143 | index 5e6e433f..c965f0e3 100644 |
| 144 | --- a/tx.c |
| 145 | +++ b/tx.c |
| 146 | @@ -837,20 +837,29 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked) |
| 147 | } |
| 148 | EXPORT_SYMBOL_GPL(__mt76_set_tx_blocked); |
| 149 | |
| 150 | -int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) |
| 151 | +int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi, |
| 152 | + u8 phy_idx) |
| 153 | { |
| 154 | - int token, start = 0; |
| 155 | + int token = -EINVAL, start = 0; |
| 156 | + struct mt76_phy *phy = mt76_dev_phy(dev, phy_idx); |
| 157 | |
| 158 | if (mtk_wed_device_active(&dev->mmio.wed)) |
| 159 | start = dev->mmio.wed.wlan.nbuf; |
| 160 | |
| 161 | spin_lock_bh(&dev->token_lock); |
| 162 | |
| 163 | + if (phy->tokens > dev->token_threshold) |
| 164 | + goto out; |
| 165 | + |
| 166 | token = idr_alloc(&dev->token, *ptxwi, start, start + dev->token_size, |
| 167 | GFP_ATOMIC); |
| 168 | - if (token >= start) |
| 169 | + if (token >= start) { |
| 170 | dev->token_count++; |
| 171 | |
| 172 | + (*ptxwi)->phy_idx = phy_idx; |
| 173 | + phy->tokens++; |
| 174 | + } |
| 175 | + |
| 176 | #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 177 | if (mtk_wed_device_active(&dev->mmio.wed) && |
| 178 | token >= dev->mmio.wed.wlan.token_start) |
| 179 | @@ -860,6 +869,7 @@ int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) |
| 180 | if (dev->token_count >= dev->token_size - MT76_TOKEN_FREE_THR) |
| 181 | __mt76_set_tx_blocked(dev, true); |
| 182 | |
| 183 | +out: |
| 184 | spin_unlock_bh(&dev->token_lock); |
| 185 | |
| 186 | return token; |
| 187 | @@ -893,7 +903,10 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake) |
| 188 | |
| 189 | txwi = idr_remove(&dev->token, token); |
| 190 | if (txwi) { |
| 191 | + struct mt76_phy *phy = mt76_dev_phy(dev, txwi->phy_idx); |
| 192 | + |
| 193 | dev->token_count--; |
| 194 | + phy->tokens--; |
| 195 | |
| 196 | #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 197 | if (mtk_wed_device_active(&dev->mmio.wed) && |
| 198 | -- |
| 199 | 2.18.0 |
| 200 | |