blob: cec5940f4ed3c547d0d49631ef2674e30a85b134 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 73508da4263fcc10cd059fd89ef4017f9725324d Mon Sep 17 00:00:00 2001
developera46f6132024-03-26 14:09:54 +08002From: Bo Jiao <Bo.Jiao@mediatek.com>
3Date: Thu, 7 Mar 2024 11:13:45 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 1046/1052] wifi: mt76: try more times when send message
developera46f6132024-03-26 14:09:54 +08005 timeout.
6
developera46f6132024-03-26 14:09:54 +08007Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
8---
9 dma.c | 7 ++++--
10 mcu.c | 66 ++++++++++++++++++++++++++++++++++++----------------
11 mt7915/mac.c | 43 +++++++++++-----------------------
12 3 files changed, 64 insertions(+), 52 deletions(-)
13
14diff --git a/dma.c b/dma.c
developer05f3b2b2024-08-19 19:17:34 +080015index bc8afcff..133a50dc 100644
developera46f6132024-03-26 14:09:54 +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
developer05f3b2b2024-08-19 19:17:34 +080042index fa4b0544..de185cc9 100644
developera46f6132024-03-26 14:09:54 +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,60 @@ 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_connac_v2(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(%d).\n",
86+ cmd, (MT76_MSG_MAX_RETRY_CNT - retry_cnt));
87+ }
88+
89+ ret = dev->mcu_ops->mcu_skb_send_msg(dev, skb_tmp, cmd, &seq);
90+ if (ret < 0 && ret != -EAGAIN)
91+ goto out;
92+
93+ if (!wait_resp) {
94+ ret = 0;
95+ goto out;
96+ }
97+
98+ expires = jiffies + dev->mcu.timeout;
99+
100+ do {
101+ skb_tmp = mt76_mcu_get_response(dev, expires);
102+ ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb_tmp, seq);
103+ if (ret == -ETIMEDOUT)
104+ break;
105+
106+ if (!ret && ret_skb)
107+ *ret_skb = skb_tmp;
108+ else
109+ dev_kfree_skb(skb_tmp);
110+
111+ if (ret != -EAGAIN)
112+ goto out;
113+ } while (ret == -EAGAIN);
114+
115+ retry_cnt--;
116 }
117
118- expires = jiffies + dev->mcu.timeout;
119-
120- do {
121- skb = mt76_mcu_get_response(dev, expires);
122- ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb, seq);
123- if (!ret && ret_skb)
124- *ret_skb = skb;
125- else
126- dev_kfree_skb(skb);
127- } while (ret == -EAGAIN);
128-
129 out:
130+ dev_kfree_skb(skb);
131 mutex_unlock(&dev->mcu.mutex);
132
133 return ret;
134diff --git a/mt7915/mac.c b/mt7915/mac.c
developer05f3b2b2024-08-19 19:17:34 +0800135index fb989405..b3c91633 100644
developera46f6132024-03-26 14:09:54 +0800136--- a/mt7915/mac.c
137+++ b/mt7915/mac.c
developera20cdc22024-05-31 18:57:31 +0800138@@ -1348,12 +1348,6 @@ mt7915_mac_restart(struct mt7915_dev *dev)
developera46f6132024-03-26 14:09:54 +0800139 }
140 }
141
142- set_bit(MT76_RESET, &dev->mphy.state);
143- set_bit(MT76_MCU_RESET, &dev->mphy.state);
144- wake_up(&dev->mt76.mcu.wait);
145- if (ext_phy)
146- set_bit(MT76_RESET, &ext_phy->state);
147-
148 /* lock/unlock all queues to ensure that no tx is pending */
149 mt76_txq_schedule_all(&dev->mphy);
150 if (ext_phy)
developera20cdc22024-05-31 18:57:31 +0800151@@ -1454,11 +1448,18 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)
developera46f6132024-03-26 14:09:54 +0800152
153 dev->recovery.hw_full_reset = true;
154
155- wake_up(&dev->mt76.mcu.wait);
156 ieee80211_stop_queues(mt76_hw(dev));
157 if (ext_phy)
158 ieee80211_stop_queues(ext_phy->hw);
159
160+ set_bit(MT76_RESET, &dev->mphy.state);
161+ set_bit(MT76_MCU_RESET, &dev->mphy.state);
162+ wake_up(&dev->mt76.mcu.wait);
163+ if (ext_phy) {
164+ set_bit(MT76_RESET, &ext_phy->state);
165+ set_bit(MT76_MCU_RESET, &ext_phy->state);
166+ }
167+
168 cancel_delayed_work_sync(&dev->mphy.mac_work);
169 if (ext_phy)
170 cancel_delayed_work_sync(&ext_phy->mac_work);
developera20cdc22024-05-31 18:57:31 +0800171@@ -1546,20 +1547,15 @@ void mt7915_mac_reset_work(struct work_struct *work)
developera46f6132024-03-26 14:09:54 +0800172
173 set_bit(MT76_RESET, &dev->mphy.state);
174 set_bit(MT76_MCU_RESET, &dev->mphy.state);
175+ if (ext_phy)
176+ set_bit(MT76_RESET, &ext_phy->state);
177 wake_up(&dev->mt76.mcu.wait);
178- cancel_delayed_work_sync(&dev->mphy.mac_work);
179- if (phy2) {
180- set_bit(MT76_RESET, &phy2->mt76->state);
181- cancel_delayed_work_sync(&phy2->mt76->mac_work);
182- }
183- cancel_delayed_work_sync(&dev->scs_work);
184+
185 mt76_worker_disable(&dev->mt76.tx_worker);
186 mt76_for_each_q_rx(&dev->mt76, i)
187 napi_disable(&dev->mt76.napi[i]);
188 napi_disable(&dev->mt76.tx_napi);
189
190- mutex_lock(&dev->mt76.mutex);
191-
192 if (mtk_wed_device_active(&dev->mt76.mmio.wed))
193 mtk_wed_device_stop(&dev->mt76.mmio.wed);
194
developera20cdc22024-05-31 18:57:31 +0800195@@ -1583,8 +1579,8 @@ void mt7915_mac_reset_work(struct work_struct *work)
developera46f6132024-03-26 14:09:54 +0800196
197 clear_bit(MT76_MCU_RESET, &dev->mphy.state);
198 clear_bit(MT76_RESET, &dev->mphy.state);
199- if (phy2)
200- clear_bit(MT76_RESET, &phy2->mt76->state);
201+ if (ext_phy)
202+ clear_bit(MT76_RESET, &ext_phy->state);
203
204 local_bh_disable();
205 mt76_for_each_q_rx(&dev->mt76, i) {
developera20cdc22024-05-31 18:57:31 +0800206@@ -1606,21 +1602,8 @@ void mt7915_mac_reset_work(struct work_struct *work)
developera46f6132024-03-26 14:09:54 +0800207 if (ext_phy)
208 ieee80211_wake_queues(ext_phy->hw);
209
210- mutex_unlock(&dev->mt76.mutex);
211-
212 mt7915_update_beacons(dev);
213
214- ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
215- MT7915_WATCHDOG_TIME);
216- if (phy2)
217- ieee80211_queue_delayed_work(ext_phy->hw,
218- &phy2->mt76->mac_work,
219- MT7915_WATCHDOG_TIME);
220-
221- if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
222- mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
223- ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
224-
225 dev_info(dev->mt76.dev,"\n%s L1 SER recovery completed.",
226 wiphy_name(dev->mt76.hw->wiphy));
227 }
228--
2292.18.0
230