blob: 937ae0cd03a984200a5e6d340ffeb8ae100cf8e1 [file] [log] [blame]
developer9237f442024-06-14 17:13:04 +08001From 3cc26e708dbef9b1eb0b5466a073a9c5c8a613b9 Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: Bo Jiao <Bo.Jiao@mediatek.com>
3Date: Mon, 6 Nov 2023 11:10:10 +0800
developer9237f442024-06-14 17:13:04 +08004Subject: [PATCH 038/116] mtk: wifi: mt76: try more times when send message
developer66e89bc2024-04-23 14:50:01 +08005 timeout.
6
developer66e89bc2024-04-23 14:50:01 +08007Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
developer66e89bc2024-04-23 14:50:01 +08008---
9 dma.c | 7 ++++--
10 mcu.c | 65 ++++++++++++++++++++++++++++++++++++----------------
11 mt7996/mac.c | 37 ++++++++++--------------------
12 3 files changed, 62 insertions(+), 47 deletions(-)
13
14diff --git a/dma.c b/dma.c
developer9237f442024-06-14 17:13:04 +080015index 5604463..66c000e 100644
developer66e89bc2024-04-23 14:50:01 +080016--- a/dma.c
17+++ b/dma.c
18@@ -504,9 +504,12 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
19 {
20 struct mt76_queue_buf buf = {};
21 dma_addr_t addr;
22+ int ret = -ENOMEM;
23
24- if (test_bit(MT76_MCU_RESET, &dev->phy.state))
25+ if (test_bit(MT76_MCU_RESET, &dev->phy.state)) {
26+ ret = -EAGAIN;
27 goto error;
28+ }
29
30 if (q->queued + 1 >= q->ndesc - 1)
31 goto error;
32@@ -528,7 +531,7 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
33
34 error:
35 dev_kfree_skb(skb);
36- return -ENOMEM;
37+ return ret;
38 }
39
40 static int
41diff --git a/mcu.c b/mcu.c
developer9237f442024-06-14 17:13:04 +080042index fa4b054..2926f71 100644
developer66e89bc2024-04-23 14:50:01 +080043--- a/mcu.c
44+++ b/mcu.c
45@@ -4,6 +4,7 @@
46 */
47
48 #include "mt76.h"
49+#include "mt76_connac.h"
50 #include <linux/moduleparam.h>
51
52 struct sk_buff *
53@@ -74,35 +75,59 @@ int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb,
54 int cmd, bool wait_resp,
55 struct sk_buff **ret_skb)
56 {
57+#define MT76_MSG_MAX_RETRY_CNT 3
58 unsigned long expires;
59- int ret, seq;
60+ int ret, seq, retry_cnt;
61+ struct sk_buff *skb_tmp;
62+ bool retry = wait_resp && is_mt7996(dev);
63
64 if (ret_skb)
65 *ret_skb = NULL;
66
67 mutex_lock(&dev->mcu.mutex);
68-
69- ret = dev->mcu_ops->mcu_skb_send_msg(dev, skb, cmd, &seq);
70- if (ret < 0)
71- goto out;
72-
73- if (!wait_resp) {
74- ret = 0;
75- goto out;
76+ retry_cnt = retry ? MT76_MSG_MAX_RETRY_CNT : 1;
77+ while (retry_cnt) {
78+ skb_tmp = mt76_mcu_msg_alloc(dev, skb->data, skb->len);
79+ if (!skb_tmp)
80+ goto out;
81+
82+ if (retry && retry_cnt < MT76_MSG_MAX_RETRY_CNT) {
83+ if (test_bit(MT76_MCU_RESET, &dev->phy.state))
84+ usleep_range(200000, 500000);
85+ dev_err(dev->dev, "send message %08x timeout, try again.\n", cmd);
86+ }
87+
88+ ret = dev->mcu_ops->mcu_skb_send_msg(dev, skb_tmp, cmd, &seq);
89+ if (ret < 0 && ret != -EAGAIN)
90+ goto out;
91+
92+ if (!wait_resp) {
93+ ret = 0;
94+ goto out;
95+ }
96+
97+ expires = jiffies + dev->mcu.timeout;
98+
99+ do {
100+ skb_tmp = mt76_mcu_get_response(dev, expires);
101+ ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb_tmp, seq);
102+ if (ret == -ETIMEDOUT)
103+ break;
104+
105+ if (!ret && ret_skb)
106+ *ret_skb = skb_tmp;
107+ else
108+ dev_kfree_skb(skb_tmp);
109+
110+ if (ret != -EAGAIN)
111+ goto out;
112+ } while (ret == -EAGAIN);
113+
114+ retry_cnt--;
115 }
116
117- expires = jiffies + dev->mcu.timeout;
118-
119- do {
120- skb = mt76_mcu_get_response(dev, expires);
121- ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb, seq);
122- if (!ret && ret_skb)
123- *ret_skb = skb;
124- else
125- dev_kfree_skb(skb);
126- } while (ret == -EAGAIN);
127-
128 out:
129+ dev_kfree_skb(skb);
130 mutex_unlock(&dev->mcu.mutex);
131
132 return ret;
133diff --git a/mt7996/mac.c b/mt7996/mac.c
developer9237f442024-06-14 17:13:04 +0800134index 4e52aa1..56827c9 100644
developer66e89bc2024-04-23 14:50:01 +0800135--- a/mt7996/mac.c
136+++ b/mt7996/mac.c
137@@ -1784,13 +1784,24 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
138 phy3 = mt7996_phy3(dev);
139 dev->recovery.hw_full_reset = true;
140
141- wake_up(&dev->mt76.mcu.wait);
142 ieee80211_stop_queues(mt76_hw(dev));
143 if (phy2)
144 ieee80211_stop_queues(phy2->mt76->hw);
145 if (phy3)
146 ieee80211_stop_queues(phy3->mt76->hw);
147
148+ set_bit(MT76_RESET, &dev->mphy.state);
149+ set_bit(MT76_MCU_RESET, &dev->mphy.state);
150+ wake_up(&dev->mt76.mcu.wait);
151+ if (phy2) {
152+ set_bit(MT76_RESET, &phy2->mt76->state);
153+ set_bit(MT76_MCU_RESET, &phy2->mt76->state);
154+ }
155+ if (phy3) {
156+ set_bit(MT76_RESET, &phy3->mt76->state);
157+ set_bit(MT76_MCU_RESET, &phy3->mt76->state);
158+ }
159+
160 cancel_work_sync(&dev->wed_rro.work);
161 cancel_delayed_work_sync(&dev->mphy.mac_work);
162 if (phy2)
163@@ -1893,16 +1904,6 @@ void mt7996_mac_reset_work(struct work_struct *work)
164 set_bit(MT76_MCU_RESET, &dev->mphy.state);
165 wake_up(&dev->mt76.mcu.wait);
166
167- cancel_work_sync(&dev->wed_rro.work);
168- cancel_delayed_work_sync(&dev->mphy.mac_work);
169- if (phy2) {
170- set_bit(MT76_RESET, &phy2->mt76->state);
171- cancel_delayed_work_sync(&phy2->mt76->mac_work);
172- }
173- if (phy3) {
174- set_bit(MT76_RESET, &phy3->mt76->state);
175- cancel_delayed_work_sync(&phy3->mt76->mac_work);
176- }
177 mt76_worker_disable(&dev->mt76.tx_worker);
178 mt76_for_each_q_rx(&dev->mt76, i) {
179 if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
180@@ -1913,8 +1914,6 @@ void mt7996_mac_reset_work(struct work_struct *work)
181 }
182 napi_disable(&dev->mt76.tx_napi);
183
184- mutex_lock(&dev->mt76.mutex);
185-
186 mt76_wr(dev, MT_MCU_INT_EVENT, MT_MCU_INT_EVENT_DMA_STOPPED);
187
188 if (mt7996_wait_reset_state(dev, MT_MCU_CMD_RESET_DONE)) {
189@@ -1987,20 +1986,8 @@ void mt7996_mac_reset_work(struct work_struct *work)
190 if (phy3)
191 ieee80211_wake_queues(phy3->mt76->hw);
192
193- mutex_unlock(&dev->mt76.mutex);
194-
195 mt7996_update_beacons(dev);
196
197- ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
198- MT7996_WATCHDOG_TIME);
199- if (phy2)
200- ieee80211_queue_delayed_work(phy2->mt76->hw,
201- &phy2->mt76->mac_work,
202- MT7996_WATCHDOG_TIME);
203- if (phy3)
204- ieee80211_queue_delayed_work(phy3->mt76->hw,
205- &phy3->mt76->mac_work,
206- MT7996_WATCHDOG_TIME);
207 dev_info(dev->mt76.dev,"\n%s L1 SER recovery completed.",
208 wiphy_name(dev->mt76.hw->wiphy));
209 }
210--
developer9237f442024-06-14 17:13:04 +08002112.18.0
developer66e89bc2024-04-23 14:50:01 +0800212