developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 1 | From a2f8deaaf6a97b0157e49ec476b003ef1dd234f8 Mon Sep 17 00:00:00 2001 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 3 | Date: Mon, 29 Jan 2024 15:33:24 +0800 |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 4 | Subject: [PATCH 13/21] wifi: mt76: mt7915: limit per-band token count |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 5 | |
| 6 | Add a threshold for per-band token count to prevent a band from interfering |
| 7 | with the other band. |
| 8 | |
| 9 | Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 10 | --- |
| 11 | mt76.h | 8 +++++++- |
| 12 | mt76_connac_mac.c | 2 ++ |
| 13 | mt7915/init.c | 3 +++ |
| 14 | mt7915/mac.c | 3 ++- |
| 15 | mt7921/pci_mac.c | 2 +- |
| 16 | mt7925/pci_mac.c | 2 +- |
| 17 | mt7996/init.c | 5 +++++ |
| 18 | mt7996/mac.c | 3 ++- |
| 19 | tx.c | 20 ++++++++++++++++++-- |
| 20 | 9 files changed, 41 insertions(+), 7 deletions(-) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 21 | |
| 22 | diff --git a/mt76.h b/mt76.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 23 | index 4fb07877..05ee568c 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 24 | --- a/mt76.h |
| 25 | +++ b/mt76.h |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 26 | @@ -407,6 +407,8 @@ struct mt76_txwi_cache { |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 27 | struct list_head list; |
| 28 | dma_addr_t dma_addr; |
| 29 | |
| 30 | + u8 phy_idx; |
| 31 | + |
| 32 | union { |
| 33 | struct sk_buff *skb; |
| 34 | void *ptr; |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 35 | @@ -819,6 +821,7 @@ struct mt76_phy { |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 36 | bool al; |
| 37 | u8 pin; |
| 38 | } leds; |
| 39 | + int tokens; |
| 40 | }; |
| 41 | |
| 42 | struct mt76_dev { |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 43 | @@ -872,6 +875,8 @@ struct mt76_dev { |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 44 | u16 wed_token_count; |
| 45 | u16 token_count; |
| 46 | u16 token_size; |
| 47 | + u16 token_threshold; |
| 48 | + u8 num_phy; |
| 49 | |
| 50 | spinlock_t rx_token_lock; |
| 51 | struct idr rx_token; |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 52 | @@ -1674,7 +1679,8 @@ static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 53 | |
| 54 | struct mt76_txwi_cache * |
| 55 | mt76_token_release(struct mt76_dev *dev, int token, bool *wake); |
| 56 | -int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi); |
| 57 | +int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi, |
| 58 | + u8 phy_idx); |
| 59 | void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); |
| 60 | struct mt76_txwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); |
| 61 | int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
developer | 2cd1216 | 2024-04-18 17:29:00 +0800 | [diff] [blame] | 62 | diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 63 | index 630c6402..a92c261d 100644 |
developer | 2cd1216 | 2024-04-18 17:29:00 +0800 | [diff] [blame] | 64 | --- a/mt76_connac_mac.c |
| 65 | +++ b/mt76_connac_mac.c |
| 66 | @@ -1178,6 +1178,8 @@ void mt76_connac2_tx_token_put(struct mt76_dev *dev) |
| 67 | idr_for_each_entry(&dev->token, txwi, id) { |
| 68 | mt76_connac2_txwi_free(dev, txwi, NULL, NULL); |
| 69 | dev->token_count--; |
| 70 | + if (dev->num_phy > 1 && dev->phys[txwi->phy_idx]) |
| 71 | + dev->phys[txwi->phy_idx]->tokens--; |
| 72 | } |
| 73 | spin_unlock_bh(&dev->token_lock); |
| 74 | idr_destroy(&dev->token); |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 75 | diff --git a/mt7915/init.c b/mt7915/init.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 76 | index 46762827..ea9bc735 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 77 | --- a/mt7915/init.c |
| 78 | +++ b/mt7915/init.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 79 | @@ -1223,6 +1223,8 @@ int mt7915_register_device(struct mt7915_dev *dev) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 80 | |
| 81 | dev->dbdc_support = mt7915_band_config(dev); |
| 82 | |
| 83 | + dev->mt76.num_phy = 1 + !!dev->dbdc_support; |
| 84 | + |
| 85 | phy2 = mt7915_alloc_ext_phy(dev); |
| 86 | if (IS_ERR(phy2)) |
| 87 | return PTR_ERR(phy2); |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 88 | @@ -1255,6 +1257,7 @@ int mt7915_register_device(struct mt7915_dev *dev) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | dev->recovery.hw_init_done = true; |
| 92 | + dev->mt76.token_threshold = dev->mt76.token_size / dev->mt76.num_phy; |
| 93 | |
| 94 | ret = mt7915_init_debugfs(&dev->phy); |
| 95 | if (ret) |
| 96 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 97 | index a5d0b096..4604a682 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 98 | --- a/mt7915/mac.c |
| 99 | +++ b/mt7915/mac.c |
| 100 | @@ -738,6 +738,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 101 | struct mt76_connac_fw_txp *txp; |
| 102 | struct mt76_txwi_cache *t; |
| 103 | int id, i, nbuf = tx_info->nbuf - 1; |
| 104 | + u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; |
| 105 | u8 *txwi = (u8 *)txwi_ptr; |
| 106 | int pid; |
| 107 | |
| 108 | @@ -761,7 +762,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 109 | t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); |
| 110 | t->skb = tx_info->skb; |
| 111 | |
| 112 | - id = mt76_token_consume(mdev, &t); |
| 113 | + id = mt76_token_consume(mdev, &t, phy_idx); |
| 114 | if (id < 0) |
| 115 | return id; |
| 116 | |
| 117 | diff --git a/mt7921/pci_mac.c b/mt7921/pci_mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 118 | index 031ba9aa..4c69c55c 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 119 | --- a/mt7921/pci_mac.c |
| 120 | +++ b/mt7921/pci_mac.c |
| 121 | @@ -27,7 +27,7 @@ int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 122 | t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); |
| 123 | t->skb = tx_info->skb; |
| 124 | |
| 125 | - id = mt76_token_consume(mdev, &t); |
| 126 | + id = mt76_token_consume(mdev, &t, 0); |
| 127 | if (id < 0) |
| 128 | return id; |
| 129 | |
| 130 | diff --git a/mt7925/pci_mac.c b/mt7925/pci_mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 131 | index 9fca8879..f1d615c0 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 132 | --- a/mt7925/pci_mac.c |
| 133 | +++ b/mt7925/pci_mac.c |
| 134 | @@ -27,7 +27,7 @@ int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 135 | t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); |
| 136 | t->skb = tx_info->skb; |
| 137 | |
| 138 | - id = mt76_token_consume(mdev, &t); |
| 139 | + id = mt76_token_consume(mdev, &t, 0); |
| 140 | if (id < 0) |
| 141 | return id; |
| 142 | |
| 143 | diff --git a/mt7996/init.c b/mt7996/init.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 144 | index 283df84f..d191a7b7 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 145 | --- a/mt7996/init.c |
| 146 | +++ b/mt7996/init.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 147 | @@ -635,6 +635,8 @@ static int mt7996_register_phy(struct mt7996_dev *dev, struct mt7996_phy *phy, |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 148 | mtk_wed_device_start(&dev->mt76.mmio.wed_hif2, irq_mask); |
| 149 | } |
| 150 | |
| 151 | + dev->mt76.num_phy++; |
| 152 | + |
| 153 | return 0; |
| 154 | |
| 155 | error: |
| 156 | @@ -1330,6 +1332,8 @@ int mt7996_register_device(struct mt7996_dev *dev) |
| 157 | if (ret) |
| 158 | return ret; |
| 159 | |
| 160 | + dev->mt76.num_phy = 1; |
| 161 | + |
| 162 | ret = mt7996_register_phy(dev, mt7996_phy2(dev), MT_BAND1); |
| 163 | if (ret) |
| 164 | return ret; |
| 165 | @@ -1342,6 +1346,7 @@ int mt7996_register_device(struct mt7996_dev *dev) |
| 166 | |
| 167 | dev->recovery.hw_init_done = true; |
| 168 | |
| 169 | + dev->mt76.token_threshold = dev->mt76.token_size / dev->mt76.num_phy; |
| 170 | ret = mt7996_init_debugfs(&dev->phy); |
| 171 | if (ret) |
| 172 | goto error; |
| 173 | diff --git a/mt7996/mac.c b/mt7996/mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 174 | index bc7111a7..aa19120b 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 175 | --- a/mt7996/mac.c |
| 176 | +++ b/mt7996/mac.c |
| 177 | @@ -922,6 +922,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 178 | struct mt76_txwi_cache *t; |
| 179 | int id, i, pid, nbuf = tx_info->nbuf - 1; |
| 180 | bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; |
| 181 | + u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; |
| 182 | u8 *txwi = (u8 *)txwi_ptr; |
| 183 | |
| 184 | if (unlikely(tx_info->skb->len <= ETH_HLEN)) |
| 185 | @@ -933,7 +934,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 186 | t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); |
| 187 | t->skb = tx_info->skb; |
| 188 | |
| 189 | - id = mt76_token_consume(mdev, &t); |
| 190 | + id = mt76_token_consume(mdev, &t, phy_idx); |
| 191 | if (id < 0) |
| 192 | return id; |
| 193 | |
| 194 | diff --git a/tx.c b/tx.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 195 | index ab42f69b..0fdf7d83 100644 |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 196 | --- a/tx.c |
| 197 | +++ b/tx.c |
| 198 | @@ -825,16 +825,30 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked) |
| 199 | } |
| 200 | EXPORT_SYMBOL_GPL(__mt76_set_tx_blocked); |
| 201 | |
| 202 | -int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) |
| 203 | +int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi, |
| 204 | + u8 phy_idx) |
| 205 | { |
| 206 | + struct mt76_phy *phy = phy_idx < __MT_MAX_BAND ? dev->phys[phy_idx] : NULL; |
| 207 | int token; |
| 208 | |
| 209 | spin_lock_bh(&dev->token_lock); |
| 210 | |
| 211 | + if (dev->num_phy > 1 && phy && phy->tokens > dev->token_threshold) { |
| 212 | + spin_unlock_bh(&dev->token_lock); |
| 213 | + |
| 214 | + return -EINVAL; |
| 215 | + } |
| 216 | + |
| 217 | token = idr_alloc(&dev->token, *ptxwi, 0, dev->token_size, GFP_ATOMIC); |
| 218 | - if (token >= 0) |
| 219 | + if (token >= 0) { |
| 220 | dev->token_count++; |
| 221 | |
| 222 | + if (dev->num_phy > 1 && phy) { |
| 223 | + (*ptxwi)->phy_idx = phy_idx; |
| 224 | + phy->tokens++; |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 229 | if (mtk_wed_device_active(&dev->mmio.wed) && |
| 230 | token >= dev->mmio.wed.wlan.token_start) |
| 231 | @@ -878,6 +892,8 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake) |
| 232 | txwi = idr_remove(&dev->token, token); |
| 233 | if (txwi) { |
| 234 | dev->token_count--; |
| 235 | + if (dev->num_phy > 1 && dev->phys[txwi->phy_idx]) |
| 236 | + dev->phys[txwi->phy_idx]->tokens--; |
| 237 | |
| 238 | #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 239 | if (mtk_wed_device_active(&dev->mmio.wed) && |
| 240 | -- |
| 241 | 2.18.0 |
| 242 | |