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