blob: 3222bb18b55faaca1b563f04b4618fff4aae50f8 [file] [log] [blame]
developer780b9152022-12-15 14:09:45 +08001From 5a4e0813aaaf66a658c9907b7834cb61e10ae682 Mon Sep 17 00:00:00 2001
developerc89c5472022-08-02 13:00:04 +08002From: Sujuan Chen <sujuan.chen@mediatek.com>
developer3d5faf22022-11-29 18:07:22 +08003Date: Fri, 25 Nov 2022 14:07:46 +0800
developer780b9152022-12-15 14:09:45 +08004Subject: [PATCH 3005/3012] mt76: mt7915: wed: add ser support when wed on
developerc89c5472022-08-02 13:00:04 +08005
6Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
7---
developer6e3b5d12022-08-16 15:37:38 +08008 dma.c | 29 ++++++++++++++++++++---------
developer3d5faf22022-11-29 18:07:22 +08009 dma.h | 1 +
developer6e3b5d12022-08-16 15:37:38 +080010 mt76.h | 1 +
developer2458e702022-12-13 15:52:04 +080011 mt7915/dma.c | 37 ++++++++++++++++++++++++++++++++-----
developer3d5faf22022-11-29 18:07:22 +080012 mt7915/mac.c | 18 ++++++++++++++++++
13 mt7915/mmio.c | 3 +++
developer6e3b5d12022-08-16 15:37:38 +080014 mt7915/mt7915.h | 1 +
developer2458e702022-12-13 15:52:04 +080015 7 files changed, 76 insertions(+), 14 deletions(-)
developerc89c5472022-08-02 13:00:04 +080016
17diff --git a/dma.c b/dma.c
developer2458e702022-12-13 15:52:04 +080018index 53c7528f..35beec72 100644
developerc89c5472022-08-02 13:00:04 +080019--- a/dma.c
20+++ b/dma.c
developer3d5faf22022-11-29 18:07:22 +080021@@ -165,7 +165,7 @@ mt76_free_pending_txwi(struct mt76_dev *dev)
developer6e3b5d12022-08-16 15:37:38 +080022 local_bh_enable();
23 }
24
25-static void
26+void
27 mt76_free_pending_rxwi(struct mt76_dev *dev)
28 {
developer3d5faf22022-11-29 18:07:22 +080029 struct mt76_txwi_cache *t;
30@@ -178,6 +178,7 @@ mt76_free_pending_rxwi(struct mt76_dev *dev)
developer6e3b5d12022-08-16 15:37:38 +080031 }
32 local_bh_enable();
33 }
34+EXPORT_SYMBOL_GPL(mt76_free_pending_rxwi);
35
36 static void
37 mt76_dma_sync_idx(struct mt76_dev *dev, struct mt76_queue *q)
developer2458e702022-12-13 15:52:04 +080038@@ -618,14 +619,18 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q)
developerc89c5472022-08-02 13:00:04 +080039 return frames;
40 }
41
42-static int
43-mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q)
44+int
45+mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset)
46 {
47 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
48 struct mtk_wed_device *wed = &dev->mmio.wed;
49 int ret, type, ring;
50- u8 flags = q->flags;
51+ u8 flags;
developer6e3b5d12022-08-16 15:37:38 +080052
developerc89c5472022-08-02 13:00:04 +080053+ if (!q || !q->ndesc)
54+ return -EINVAL;
developer6e3b5d12022-08-16 15:37:38 +080055+
developerc89c5472022-08-02 13:00:04 +080056+ flags = q->flags;
57 if (!mtk_wed_device_active(wed))
58 q->flags &= ~MT_QFLAG_WED;
59
developer2458e702022-12-13 15:52:04 +080060@@ -637,7 +642,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q)
developerc89c5472022-08-02 13:00:04 +080061
62 switch (type) {
63 case MT76_WED_Q_TX:
64- ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs);
65+ ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs, reset);
66 if (!ret)
67 q->wed_regs = wed->tx_ring[ring].reg_base;
68 break;
developer2458e702022-12-13 15:52:04 +080069@@ -653,7 +658,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q)
developerc89c5472022-08-02 13:00:04 +080070 q->wed_regs = wed->txfree_ring.reg_base;
71 break;
72 case MT76_WED_Q_RX:
73- ret = mtk_wed_device_rx_ring_setup(wed, ring, q->regs);
74+ ret = mtk_wed_device_rx_ring_setup(wed, ring, q->regs, reset);
75 if (!ret)
76 q->wed_regs = wed->rx_ring[ring].reg_base;
77 break;
developer2458e702022-12-13 15:52:04 +080078@@ -666,6 +671,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q)
developerc89c5472022-08-02 13:00:04 +080079 return 0;
80 #endif
81 }
82+EXPORT_SYMBOL_GPL(mt76_dma_wed_setup);
83
84 static int
85 mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q,
developer2458e702022-12-13 15:52:04 +080086@@ -692,7 +698,7 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q,
developerc89c5472022-08-02 13:00:04 +080087 if (!q->entry)
88 return -ENOMEM;
89
90- ret = mt76_dma_wed_setup(dev, q);
91+ ret = mt76_dma_wed_setup(dev, q, false);
92 if (ret)
93 return ret;
94
developer2458e702022-12-13 15:52:04 +080095@@ -743,8 +749,13 @@ mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid)
developerc89c5472022-08-02 13:00:04 +080096 q->desc[i].ctrl = cpu_to_le32(MT_DMA_CTL_DMA_DONE);
97
98 mt76_dma_rx_cleanup(dev, q);
99- mt76_dma_sync_idx(dev, q);
100- mt76_dma_rx_fill(dev, q);
101+
102+ mt76_dma_wed_setup(dev, q, true);
103+
104+ if (q->flags != MT_WED_Q_TXFREE) {
105+ mt76_dma_sync_idx(dev, q);
106+ mt76_dma_rx_fill(dev, q);
107+ }
108
109 if (!q->rx_head)
110 return;
111diff --git a/dma.h b/dma.h
developer3d5faf22022-11-29 18:07:22 +0800112index 53c6ce25..4b9bc7f4 100644
developerc89c5472022-08-02 13:00:04 +0800113--- a/dma.h
114+++ b/dma.h
developer3d5faf22022-11-29 18:07:22 +0800115@@ -56,5 +56,6 @@ enum mt76_mcu_evt_type {
developerc89c5472022-08-02 13:00:04 +0800116 int mt76_dma_rx_poll(struct napi_struct *napi, int budget);
117 void mt76_dma_attach(struct mt76_dev *dev);
118 void mt76_dma_cleanup(struct mt76_dev *dev);
developerc89c5472022-08-02 13:00:04 +0800119+int mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset);
developer3d5faf22022-11-29 18:07:22 +0800120
developerc89c5472022-08-02 13:00:04 +0800121 #endif
developer6e3b5d12022-08-16 15:37:38 +0800122diff --git a/mt76.h b/mt76.h
developer780b9152022-12-15 14:09:45 +0800123index 7b222e73..75975cb5 100644
developer6e3b5d12022-08-16 15:37:38 +0800124--- a/mt76.h
125+++ b/mt76.h
developer780b9152022-12-15 14:09:45 +0800126@@ -1395,6 +1395,7 @@ mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb)
developer6e3b5d12022-08-16 15:37:38 +0800127 void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);
128 void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);
129 struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev);
130+void mt76_free_pending_rxwi(struct mt76_dev *dev);
131 void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
132 struct napi_struct *napi);
133 void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
developerc89c5472022-08-02 13:00:04 +0800134diff --git a/mt7915/dma.c b/mt7915/dma.c
developer2458e702022-12-13 15:52:04 +0800135index e3fa0649..1ae6c339 100644
developerc89c5472022-08-02 13:00:04 +0800136--- a/mt7915/dma.c
137+++ b/mt7915/dma.c
developer2458e702022-12-13 15:52:04 +0800138@@ -4,6 +4,7 @@
139 #include "mt7915.h"
140 #include "../dma.h"
141 #include "mac.h"
142+#include <linux/rtnetlink.h>
143
144 static int
145 mt7915_init_tx_queues(struct mt7915_phy *phy, int idx, int n_desc, int ring_base)
146@@ -562,6 +563,7 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2)
developer6e3b5d12022-08-16 15:37:38 +0800147 int mt7915_dma_reset(struct mt7915_dev *dev, bool force)
148 {
developer4df64ba2022-09-01 14:44:55 +0800149 struct mt76_phy *mphy_ext = dev->mt76.phys[MT_BAND1];
developer6e3b5d12022-08-16 15:37:38 +0800150+ struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
151 int i;
152
153 /* clean up hw queues */
developer2458e702022-12-13 15:52:04 +0800154@@ -581,28 +583,53 @@ int mt7915_dma_reset(struct mt7915_dev *dev, bool force)
developer2cbf2fb2022-11-16 12:20:48 +0800155 if (force)
developerc89c5472022-08-02 13:00:04 +0800156 mt7915_wfsys_reset(dev);
157
developerc89c5472022-08-02 13:00:04 +0800158+ if (mtk_wed_device_active(&dev->mt76.mmio.wed))
159+ mtk_wed_device_dma_reset(&dev->mt76.mmio.wed);
160 mt7915_dma_disable(dev, force);
161
developer6e3b5d12022-08-16 15:37:38 +0800162+ /* set wifi reset done, wait FE reset */
163+ if (mtk_wed_device_active(wed) && atomic_read(&wed->fe_reset)) {
164+ atomic_set(&wed->fe_reset, 0);
165+ rtnl_lock();
166+ complete(&wed->wlan_reset_done);
167+ rtnl_unlock();
168+ wait_for_completion(&wed->fe_reset_done);
169+ }
170+
developerc89c5472022-08-02 13:00:04 +0800171 /* reset hw queues */
172 for (i = 0; i < __MT_TXQ_MAX; i++) {
173 mt76_queue_reset(dev, dev->mphy.q_tx[i]);
174- if (mphy_ext)
175+ if (mphy_ext) {
176 mt76_queue_reset(dev, mphy_ext->q_tx[i]);
developer6e3b5d12022-08-16 15:37:38 +0800177+ if (mtk_wed_device_active(wed))
developerc89c5472022-08-02 13:00:04 +0800178+ mt76_dma_wed_setup(&dev->mt76,
179+ mphy_ext->q_tx[i],
180+ true);
181+ }
developer6e3b5d12022-08-16 15:37:38 +0800182+ if (mtk_wed_device_active(wed))
developerc89c5472022-08-02 13:00:04 +0800183+ mt76_dma_wed_setup(&dev->mt76, dev->mphy.q_tx[i],
184+ true);
185 }
186
187 for (i = 0; i < __MT_MCUQ_MAX; i++)
188 mt76_queue_reset(dev, dev->mt76.q_mcu[i]);
189
190- mt76_for_each_q_rx(&dev->mt76, i)
191- mt76_queue_reset(dev, &dev->mt76.q_rx[i]);
192+ mt76_for_each_q_rx(&dev->mt76, i) {
193+ if (dev->mt76.q_rx[i].flags != MT_WED_Q_TXFREE)
194+ mt76_queue_reset(dev, &dev->mt76.q_rx[i]);
195+ }
196
197 mt76_tx_status_check(&dev->mt76, true);
198
199- mt7915_dma_enable(dev);
200-
201 mt76_for_each_q_rx(&dev->mt76, i)
202 mt76_queue_rx_reset(dev, i);
203
developer6e3b5d12022-08-16 15:37:38 +0800204+ if(mtk_wed_device_active(wed) && is_mt7915(&dev->mt76))
developerc89c5472022-08-02 13:00:04 +0800205+ mt76_rmw(dev, MT_WFDMA0_EXT0_CFG, MT_WFDMA0_EXT0_RXWB_KEEP,
206+ MT_WFDMA0_EXT0_RXWB_KEEP);
207+
208+ mt7915_dma_enable(dev);
209+
210 return 0;
211 }
212
213diff --git a/mt7915/mac.c b/mt7915/mac.c
developer2458e702022-12-13 15:52:04 +0800214index 5373777a..d5df73db 100644
developerc89c5472022-08-02 13:00:04 +0800215--- a/mt7915/mac.c
216+++ b/mt7915/mac.c
developer2458e702022-12-13 15:52:04 +0800217@@ -894,6 +894,18 @@ u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id)
developer3d5faf22022-11-29 18:07:22 +0800218 return MT_TXD_TXP_BUF_SIZE;
developer6e3b5d12022-08-16 15:37:38 +0800219 }
220
221+void mt7915_wed_trigger_ser(struct mtk_wed_device *wed)
222+{
223+ struct mt7915_dev *dev;
224+ u8 band_idx;
225+ dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
developer2458e702022-12-13 15:52:04 +0800226+ band_idx = dev->phy.mt76->band_idx;
developer6e3b5d12022-08-16 15:37:38 +0800227+
228+ mt7915_mcu_set_ser(dev, SER_RECOVER, 1, band_idx);
229+
230+ return;
231+}
232+
233 static void
234 mt7915_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
235 {
developer3d5faf22022-11-29 18:07:22 +0800236@@ -1633,6 +1645,12 @@ void mt7915_mac_reset_work(struct work_struct *work)
developer2cbf2fb2022-11-16 12:20:48 +0800237 if (!(READ_ONCE(dev->recovery.state) & MT_MCU_CMD_STOP_DMA))
developerc89c5472022-08-02 13:00:04 +0800238 return;
239
240+ if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
241+ mtk_wed_device_stop(&dev->mt76.mmio.wed, true);
242+ if (!is_mt7986(&dev->mt76))
243+ mt76_wr(dev, MT_INT_WED_MASK_CSR, 0);
244+ }
245+
246 ieee80211_stop_queues(mt76_hw(dev));
247 if (ext_phy)
248 ieee80211_stop_queues(ext_phy->hw);
developer6e3b5d12022-08-16 15:37:38 +0800249diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developer780b9152022-12-15 14:09:45 +0800250index ac574722..ecc38e05 100644
developer6e3b5d12022-08-16 15:37:38 +0800251--- a/mt7915/mmio.c
252+++ b/mt7915/mmio.c
developer2458e702022-12-13 15:52:04 +0800253@@ -617,6 +617,8 @@ static void mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device *wed)
developer3d5faf22022-11-29 18:07:22 +0800254 mt76_put_rxwi(&dev->mt76, t);
255 }
256
257+ mt76_free_pending_rxwi(&dev->mt76);
258+
259 if (!wed->rx_buf_ring.rx_page.va)
260 return;
261
developer2458e702022-12-13 15:52:04 +0800262@@ -782,6 +784,7 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr,
263 wed->wlan.init_rx_buf = mt7915_mmio_wed_init_rx_buf;
264 wed->wlan.release_rx_buf = mt7915_mmio_wed_release_rx_buf;
developer3d5faf22022-11-29 18:07:22 +0800265 wed->wlan.update_wo_rx_stats = mt7915_mmio_wed_update_rx_stats;
developer6e3b5d12022-08-16 15:37:38 +0800266+ wed->wlan.ser_trigger = mt7915_wed_trigger_ser;
developer3d5faf22022-11-29 18:07:22 +0800267
268 dev->mt76.rx_token_size = wed->wlan.rx_npkt;
269
developer6e3b5d12022-08-16 15:37:38 +0800270diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer780b9152022-12-15 14:09:45 +0800271index 2e6519e7..f9c02912 100644
developer6e3b5d12022-08-16 15:37:38 +0800272--- a/mt7915/mt7915.h
273+++ b/mt7915/mt7915.h
developer780b9152022-12-15 14:09:45 +0800274@@ -559,6 +559,7 @@ void mt7915_wfsys_reset(struct mt7915_dev *dev);
developer3d5faf22022-11-29 18:07:22 +0800275 irqreturn_t mt7915_irq_handler(int irq, void *dev_instance);
276 u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif);
277 u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id);
developer6e3b5d12022-08-16 15:37:38 +0800278+void mt7915_wed_trigger_ser(struct mtk_wed_device *wed);
developer3d5faf22022-11-29 18:07:22 +0800279
developer6e3b5d12022-08-16 15:37:38 +0800280 int mt7915_register_device(struct mt7915_dev *dev);
281 void mt7915_unregister_device(struct mt7915_dev *dev);
developerc89c5472022-08-02 13:00:04 +0800282--
developer2458e702022-12-13 15:52:04 +08002832.25.1
developerc89c5472022-08-02 13:00:04 +0800284