developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 1 | From fcd960471fe61d47225ac1da974e64a2700cd797 Mon Sep 17 00:00:00 2001 |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 2 | From: Sujuan Chen <sujuan.chen@mediatek.com> |
| 3 | Date: Thu, 28 Jul 2022 11:16:15 +0800 |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 4 | Subject: [PATCH 3005/3010] mt76 add ser spport when wed on |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com> |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 7 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 8 | --- |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 9 | dma.c | 29 ++++++++++++++++++++--------- |
| 10 | dma.h | 2 +- |
| 11 | mt76.h | 1 + |
| 12 | mt7915/dma.c | 36 +++++++++++++++++++++++++++++++----- |
| 13 | mt7915/mac.c | 20 ++++++++++++++++++++ |
| 14 | mt7915/mmio.c | 2 ++ |
| 15 | mt7915/mt7915.h | 1 + |
| 16 | 7 files changed, 76 insertions(+), 15 deletions(-) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 17 | |
| 18 | diff --git a/dma.c b/dma.c |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 19 | index a8739eb..d63b02f 100644 |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 20 | --- a/dma.c |
| 21 | +++ b/dma.c |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 22 | @@ -169,7 +169,7 @@ mt76_free_pending_txwi(struct mt76_dev *dev) |
| 23 | local_bh_enable(); |
| 24 | } |
| 25 | |
| 26 | -static void |
| 27 | +void |
| 28 | mt76_free_pending_rxwi(struct mt76_dev *dev) |
| 29 | { |
| 30 | struct mt76_txwi_cache *r; |
| 31 | @@ -183,6 +183,7 @@ mt76_free_pending_rxwi(struct mt76_dev *dev) |
| 32 | } |
| 33 | local_bh_enable(); |
| 34 | } |
| 35 | +EXPORT_SYMBOL_GPL(mt76_free_pending_rxwi); |
| 36 | |
| 37 | static void |
| 38 | mt76_dma_sync_idx(struct mt76_dev *dev, struct mt76_queue *q) |
| 39 | @@ -624,14 +625,18 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 40 | return frames; |
| 41 | } |
| 42 | |
| 43 | -static int |
| 44 | -mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q) |
| 45 | +int |
| 46 | +mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset) |
| 47 | { |
| 48 | #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 49 | struct mtk_wed_device *wed = &dev->mmio.wed; |
| 50 | int ret, type, ring; |
| 51 | - u8 flags = q->flags; |
| 52 | + u8 flags; |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 53 | |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 54 | + if (!q || !q->ndesc) |
| 55 | + return -EINVAL; |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 56 | + |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 57 | + flags = q->flags; |
| 58 | if (!mtk_wed_device_active(wed)) |
| 59 | q->flags &= ~MT_QFLAG_WED; |
| 60 | |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 61 | @@ -643,7 +648,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 62 | |
| 63 | switch (type) { |
| 64 | case MT76_WED_Q_TX: |
| 65 | - ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs); |
| 66 | + ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs, reset); |
| 67 | if (!ret) |
| 68 | q->wed_regs = wed->tx_ring[ring].reg_base; |
| 69 | break; |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 70 | @@ -659,7 +664,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 71 | q->wed_regs = wed->txfree_ring.reg_base; |
| 72 | break; |
| 73 | case MT76_WED_Q_RX: |
| 74 | - ret = mtk_wed_device_rx_ring_setup(wed, ring, q->regs); |
| 75 | + ret = mtk_wed_device_rx_ring_setup(wed, ring, q->regs, reset); |
| 76 | if (!ret) |
| 77 | q->wed_regs = wed->rx_ring[ring].reg_base; |
| 78 | break; |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 79 | @@ -672,6 +677,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 80 | return 0; |
| 81 | #endif |
| 82 | } |
| 83 | +EXPORT_SYMBOL_GPL(mt76_dma_wed_setup); |
| 84 | |
| 85 | static int |
| 86 | mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q, |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 87 | @@ -704,7 +710,7 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 88 | if (!q->entry) |
| 89 | return -ENOMEM; |
| 90 | |
| 91 | - ret = mt76_dma_wed_setup(dev, q); |
| 92 | + ret = mt76_dma_wed_setup(dev, q, false); |
| 93 | if (ret) |
| 94 | return ret; |
| 95 | |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 96 | @@ -755,8 +761,13 @@ mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 97 | q->desc[i].ctrl = cpu_to_le32(MT_DMA_CTL_DMA_DONE); |
| 98 | |
| 99 | mt76_dma_rx_cleanup(dev, q); |
| 100 | - mt76_dma_sync_idx(dev, q); |
| 101 | - mt76_dma_rx_fill(dev, q); |
| 102 | + |
| 103 | + mt76_dma_wed_setup(dev, q, true); |
| 104 | + |
| 105 | + if (q->flags != MT_WED_Q_TXFREE) { |
| 106 | + mt76_dma_sync_idx(dev, q); |
| 107 | + mt76_dma_rx_fill(dev, q); |
| 108 | + } |
| 109 | |
| 110 | if (!q->rx_head) |
| 111 | return; |
| 112 | diff --git a/dma.h b/dma.h |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 113 | index 90370d1..083cbca 100644 |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 114 | --- a/dma.h |
| 115 | +++ b/dma.h |
| 116 | @@ -58,5 +58,5 @@ enum mt76_mcu_evt_type { |
| 117 | int mt76_dma_rx_poll(struct napi_struct *napi, int budget); |
| 118 | void mt76_dma_attach(struct mt76_dev *dev); |
| 119 | void mt76_dma_cleanup(struct mt76_dev *dev); |
| 120 | - |
| 121 | +int mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset); |
| 122 | #endif |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 123 | diff --git a/mt76.h b/mt76.h |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 124 | index 45439a7..13bdc08 100644 |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 125 | --- a/mt76.h |
| 126 | +++ b/mt76.h |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 127 | @@ -1373,6 +1373,7 @@ mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb) |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 128 | void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); |
| 129 | void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); |
| 130 | struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev); |
| 131 | +void mt76_free_pending_rxwi(struct mt76_dev *dev); |
| 132 | void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, |
| 133 | struct napi_struct *napi); |
| 134 | void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q, |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 135 | diff --git a/mt7915/dma.c b/mt7915/dma.c |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 136 | index 702d629..96cad2b 100644 |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 137 | --- a/mt7915/dma.c |
| 138 | +++ b/mt7915/dma.c |
developer | ec56711 | 2022-10-11 11:02:55 +0800 | [diff] [blame] | 139 | @@ -532,6 +532,7 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 140 | int mt7915_dma_reset(struct mt7915_dev *dev, bool force) |
| 141 | { |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 142 | struct mt76_phy *mphy_ext = dev->mt76.phys[MT_BAND1]; |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 143 | + struct mtk_wed_device *wed = &dev->mt76.mmio.wed; |
| 144 | int i; |
| 145 | |
| 146 | /* clean up hw queues */ |
developer | ec56711 | 2022-10-11 11:02:55 +0800 | [diff] [blame] | 147 | @@ -552,28 +553,53 @@ int mt7915_dma_reset(struct mt7915_dev *dev, bool force) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 148 | mt7915_wfsys_reset(dev); |
| 149 | |
| 150 | /* disable wfdma */ |
| 151 | + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) |
| 152 | + mtk_wed_device_dma_reset(&dev->mt76.mmio.wed); |
| 153 | mt7915_dma_disable(dev, force); |
| 154 | |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 155 | + /* set wifi reset done, wait FE reset */ |
| 156 | + if (mtk_wed_device_active(wed) && atomic_read(&wed->fe_reset)) { |
| 157 | + atomic_set(&wed->fe_reset, 0); |
| 158 | + rtnl_lock(); |
| 159 | + complete(&wed->wlan_reset_done); |
| 160 | + rtnl_unlock(); |
| 161 | + wait_for_completion(&wed->fe_reset_done); |
| 162 | + } |
| 163 | + |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 164 | /* reset hw queues */ |
| 165 | for (i = 0; i < __MT_TXQ_MAX; i++) { |
| 166 | mt76_queue_reset(dev, dev->mphy.q_tx[i]); |
| 167 | - if (mphy_ext) |
| 168 | + if (mphy_ext) { |
| 169 | mt76_queue_reset(dev, mphy_ext->q_tx[i]); |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 170 | + if (mtk_wed_device_active(wed)) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 171 | + mt76_dma_wed_setup(&dev->mt76, |
| 172 | + mphy_ext->q_tx[i], |
| 173 | + true); |
| 174 | + } |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 175 | + if (mtk_wed_device_active(wed)) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 176 | + mt76_dma_wed_setup(&dev->mt76, dev->mphy.q_tx[i], |
| 177 | + true); |
| 178 | } |
| 179 | |
| 180 | for (i = 0; i < __MT_MCUQ_MAX; i++) |
| 181 | mt76_queue_reset(dev, dev->mt76.q_mcu[i]); |
| 182 | |
| 183 | - mt76_for_each_q_rx(&dev->mt76, i) |
| 184 | - mt76_queue_reset(dev, &dev->mt76.q_rx[i]); |
| 185 | + mt76_for_each_q_rx(&dev->mt76, i) { |
| 186 | + if (dev->mt76.q_rx[i].flags != MT_WED_Q_TXFREE) |
| 187 | + mt76_queue_reset(dev, &dev->mt76.q_rx[i]); |
| 188 | + } |
| 189 | |
| 190 | mt76_tx_status_check(&dev->mt76, true); |
| 191 | |
| 192 | - mt7915_dma_enable(dev); |
| 193 | - |
| 194 | mt76_for_each_q_rx(&dev->mt76, i) |
| 195 | mt76_queue_rx_reset(dev, i); |
| 196 | |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 197 | + if(mtk_wed_device_active(wed) && is_mt7915(&dev->mt76)) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 198 | + mt76_rmw(dev, MT_WFDMA0_EXT0_CFG, MT_WFDMA0_EXT0_RXWB_KEEP, |
| 199 | + MT_WFDMA0_EXT0_RXWB_KEEP); |
| 200 | + |
| 201 | + mt7915_dma_enable(dev); |
| 202 | + |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 207 | index 1ef7cb4..e78f30f 100644 |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 208 | --- a/mt7915/mac.c |
| 209 | +++ b/mt7915/mac.c |
developer | f10a898 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 210 | @@ -918,6 +918,8 @@ void mt7915_wed_release_rx_buf(struct mtk_wed_device *wed) |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 211 | mt76_put_rxwi(&dev->mt76, rxwi); |
| 212 | } |
| 213 | |
| 214 | + mt76_free_pending_rxwi(&dev->mt76); |
| 215 | + |
| 216 | if (wed->rx_page.va) |
| 217 | return; |
| 218 | |
developer | f10a898 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 219 | @@ -928,6 +930,18 @@ void mt7915_wed_release_rx_buf(struct mtk_wed_device *wed) |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 220 | return; |
| 221 | } |
| 222 | |
| 223 | +void mt7915_wed_trigger_ser(struct mtk_wed_device *wed) |
| 224 | +{ |
| 225 | + struct mt7915_dev *dev; |
| 226 | + u8 band_idx; |
| 227 | + dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 228 | + band_idx = dev->phy.band_idx; |
| 229 | + |
| 230 | + mt7915_mcu_set_ser(dev, SER_RECOVER, 1, band_idx); |
| 231 | + |
| 232 | + return; |
| 233 | +} |
| 234 | + |
| 235 | static void |
| 236 | mt7915_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi) |
| 237 | { |
developer | f10a898 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 238 | @@ -1681,6 +1695,12 @@ void mt7915_mac_reset_work(struct work_struct *work) |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 239 | if (!(READ_ONCE(dev->reset_state) & MT_MCU_CMD_STOP_DMA)) |
| 240 | return; |
| 241 | |
| 242 | + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { |
| 243 | + mtk_wed_device_stop(&dev->mt76.mmio.wed, true); |
| 244 | + if (!is_mt7986(&dev->mt76)) |
| 245 | + mt76_wr(dev, MT_INT_WED_MASK_CSR, 0); |
| 246 | + } |
| 247 | + |
| 248 | ieee80211_stop_queues(mt76_hw(dev)); |
| 249 | if (ext_phy) |
| 250 | ieee80211_stop_queues(ext_phy->hw); |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 251 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 252 | index 45520c7..6a1877d 100644 |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 253 | --- a/mt7915/mmio.c |
| 254 | +++ b/mt7915/mmio.c |
developer | f10a898 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 255 | @@ -616,6 +616,8 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr, |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 256 | wed->wlan.init_rx_buf = mt7915_wed_init_rx_buf; |
| 257 | wed->wlan.release_rx_buf = mt7915_wed_release_rx_buf; |
| 258 | |
| 259 | + wed->wlan.ser_trigger = mt7915_wed_trigger_ser; |
| 260 | + |
| 261 | dev->mt76.rx_token_size = wed->wlan.rx_pkt; |
developer | ec56711 | 2022-10-11 11:02:55 +0800 | [diff] [blame] | 262 | if (mtk_wed_device_attach(wed)) |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 263 | return 0; |
| 264 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 265 | index 346571a..412f4f4 100644 |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 266 | --- a/mt7915/mt7915.h |
| 267 | +++ b/mt7915/mt7915.h |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 268 | @@ -548,6 +548,7 @@ u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id); |
developer | f2548b0 | 2022-08-16 15:37:38 +0800 | [diff] [blame] | 269 | u32 mt7915_wed_init_rx_buf(struct mtk_wed_device *wed, |
| 270 | int pkt_num); |
| 271 | void mt7915_wed_release_rx_buf(struct mtk_wed_device *wed); |
| 272 | +void mt7915_wed_trigger_ser(struct mtk_wed_device *wed); |
| 273 | int mt7915_register_device(struct mt7915_dev *dev); |
| 274 | void mt7915_unregister_device(struct mt7915_dev *dev); |
developer | f10a898 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 275 | void mt7915_eeprom_rebonding(struct mt7915_dev *dev); |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 276 | -- |
developer | b403ad0 | 2022-11-08 10:16:29 +0800 | [diff] [blame] | 277 | 2.18.0 |
developer | 63541d2 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 278 | |