blob: ed1ac982f8463a6266a8e904af92dade44fe8f5e [file] [log] [blame]
developer3f52c302024-04-08 14:36:46 +08001From b0e4d25607d3a52f93139919c85482f87087f145 Mon Sep 17 00:00:00 2001
developer43a264f2024-03-26 14:09:54 +08002From: Bo Jiao <Bo.Jiao@mediatek.com>
3Date: Thu, 7 Mar 2024 11:13:45 +0800
developer3f52c302024-04-08 14:36:46 +08004Subject: [PATCH 1047/1053] wifi: mt76: try more times when send message
developer43a264f2024-03-26 14:09:54 +08005 timeout.
6
7CR-Id: WCNCR00334773
8Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
9---
10 dma.c | 7 ++++--
11 mcu.c | 66 ++++++++++++++++++++++++++++++++++++----------------
12 mt7915/mac.c | 43 +++++++++++-----------------------
13 3 files changed, 64 insertions(+), 52 deletions(-)
14
15diff --git a/dma.c b/dma.c
developer3f52c302024-04-08 14:36:46 +080016index bc8afcf..133a50d 100644
developer43a264f2024-03-26 14:09:54 +080017--- a/dma.c
18+++ b/dma.c
19@@ -504,9 +504,12 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
20 {
21 struct mt76_queue_buf buf = {};
22 dma_addr_t addr;
23+ int ret = -ENOMEM;
24
25- if (test_bit(MT76_MCU_RESET, &dev->phy.state))
26+ if (test_bit(MT76_MCU_RESET, &dev->phy.state)) {
27+ ret = -EAGAIN;
28 goto error;
29+ }
30
31 if (q->queued + 1 >= q->ndesc - 1)
32 goto error;
33@@ -528,7 +531,7 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
34
35 error:
36 dev_kfree_skb(skb);
37- return -ENOMEM;
38+ return ret;
39 }
40
41 static int
42diff --git a/mcu.c b/mcu.c
developer3f52c302024-04-08 14:36:46 +080043index fa4b054..de185cc 100644
developer43a264f2024-03-26 14:09:54 +080044--- a/mcu.c
45+++ b/mcu.c
46@@ -4,6 +4,7 @@
47 */
48
49 #include "mt76.h"
50+#include "mt76_connac.h"
51 #include <linux/moduleparam.h>
52
53 struct sk_buff *
54@@ -74,35 +75,60 @@ int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb,
55 int cmd, bool wait_resp,
56 struct sk_buff **ret_skb)
57 {
58+#define MT76_MSG_MAX_RETRY_CNT 3
59 unsigned long expires;
60- int ret, seq;
61+ int ret, seq, retry_cnt;
62+ struct sk_buff *skb_tmp;
63+ bool retry = wait_resp && is_connac_v2(dev);
64
65 if (ret_skb)
66 *ret_skb = NULL;
67
68 mutex_lock(&dev->mcu.mutex);
69-
70- ret = dev->mcu_ops->mcu_skb_send_msg(dev, skb, cmd, &seq);
71- if (ret < 0)
72- goto out;
73-
74- if (!wait_resp) {
75- ret = 0;
76- goto out;
77+ retry_cnt = retry ? MT76_MSG_MAX_RETRY_CNT : 1;
78+ while (retry_cnt) {
79+ skb_tmp = mt76_mcu_msg_alloc(dev, skb->data, skb->len);
80+ if (!skb_tmp)
81+ goto out;
82+
83+ if (retry && retry_cnt < MT76_MSG_MAX_RETRY_CNT) {
84+ if (test_bit(MT76_MCU_RESET, &dev->phy.state))
85+ usleep_range(200000, 500000);
86+ dev_err(dev->dev, "send message %08x timeout, try again(%d).\n",
87+ cmd, (MT76_MSG_MAX_RETRY_CNT - retry_cnt));
88+ }
89+
90+ ret = dev->mcu_ops->mcu_skb_send_msg(dev, skb_tmp, cmd, &seq);
91+ if (ret < 0 && ret != -EAGAIN)
92+ goto out;
93+
94+ if (!wait_resp) {
95+ ret = 0;
96+ goto out;
97+ }
98+
99+ expires = jiffies + dev->mcu.timeout;
100+
101+ do {
102+ skb_tmp = mt76_mcu_get_response(dev, expires);
103+ ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb_tmp, seq);
104+ if (ret == -ETIMEDOUT)
105+ break;
106+
107+ if (!ret && ret_skb)
108+ *ret_skb = skb_tmp;
109+ else
110+ dev_kfree_skb(skb_tmp);
111+
112+ if (ret != -EAGAIN)
113+ goto out;
114+ } while (ret == -EAGAIN);
115+
116+ retry_cnt--;
117 }
118
119- expires = jiffies + dev->mcu.timeout;
120-
121- do {
122- skb = mt76_mcu_get_response(dev, expires);
123- ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb, seq);
124- if (!ret && ret_skb)
125- *ret_skb = skb;
126- else
127- dev_kfree_skb(skb);
128- } while (ret == -EAGAIN);
129-
130 out:
131+ dev_kfree_skb(skb);
132 mutex_unlock(&dev->mcu.mutex);
133
134 return ret;
135diff --git a/mt7915/mac.c b/mt7915/mac.c
developer3f52c302024-04-08 14:36:46 +0800136index 2e4a8f8..dbc1095 100644
developer43a264f2024-03-26 14:09:54 +0800137--- a/mt7915/mac.c
138+++ b/mt7915/mac.c
139@@ -1389,12 +1389,6 @@ mt7915_mac_restart(struct mt7915_dev *dev)
140 }
141 }
142
143- set_bit(MT76_RESET, &dev->mphy.state);
144- set_bit(MT76_MCU_RESET, &dev->mphy.state);
145- wake_up(&dev->mt76.mcu.wait);
146- if (ext_phy)
147- set_bit(MT76_RESET, &ext_phy->state);
148-
149 /* lock/unlock all queues to ensure that no tx is pending */
150 mt76_txq_schedule_all(&dev->mphy);
151 if (ext_phy)
152@@ -1495,11 +1489,18 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)
153
154 dev->recovery.hw_full_reset = true;
155
156- wake_up(&dev->mt76.mcu.wait);
157 ieee80211_stop_queues(mt76_hw(dev));
158 if (ext_phy)
159 ieee80211_stop_queues(ext_phy->hw);
160
161+ set_bit(MT76_RESET, &dev->mphy.state);
162+ set_bit(MT76_MCU_RESET, &dev->mphy.state);
163+ wake_up(&dev->mt76.mcu.wait);
164+ if (ext_phy) {
165+ set_bit(MT76_RESET, &ext_phy->state);
166+ set_bit(MT76_MCU_RESET, &ext_phy->state);
167+ }
168+
169 cancel_delayed_work_sync(&dev->mphy.mac_work);
170 if (ext_phy)
171 cancel_delayed_work_sync(&ext_phy->mac_work);
172@@ -1587,20 +1588,15 @@ void mt7915_mac_reset_work(struct work_struct *work)
173
174 set_bit(MT76_RESET, &dev->mphy.state);
175 set_bit(MT76_MCU_RESET, &dev->mphy.state);
176+ if (ext_phy)
177+ set_bit(MT76_RESET, &ext_phy->state);
178 wake_up(&dev->mt76.mcu.wait);
179- cancel_delayed_work_sync(&dev->mphy.mac_work);
180- if (phy2) {
181- set_bit(MT76_RESET, &phy2->mt76->state);
182- cancel_delayed_work_sync(&phy2->mt76->mac_work);
183- }
184- cancel_delayed_work_sync(&dev->scs_work);
185+
186 mt76_worker_disable(&dev->mt76.tx_worker);
187 mt76_for_each_q_rx(&dev->mt76, i)
188 napi_disable(&dev->mt76.napi[i]);
189 napi_disable(&dev->mt76.tx_napi);
190
191- mutex_lock(&dev->mt76.mutex);
192-
193 if (mtk_wed_device_active(&dev->mt76.mmio.wed))
194 mtk_wed_device_stop(&dev->mt76.mmio.wed);
195
196@@ -1624,8 +1620,8 @@ void mt7915_mac_reset_work(struct work_struct *work)
197
198 clear_bit(MT76_MCU_RESET, &dev->mphy.state);
199 clear_bit(MT76_RESET, &dev->mphy.state);
200- if (phy2)
201- clear_bit(MT76_RESET, &phy2->mt76->state);
202+ if (ext_phy)
203+ clear_bit(MT76_RESET, &ext_phy->state);
204
205 local_bh_disable();
206 mt76_for_each_q_rx(&dev->mt76, i) {
207@@ -1647,21 +1643,8 @@ void mt7915_mac_reset_work(struct work_struct *work)
208 if (ext_phy)
209 ieee80211_wake_queues(ext_phy->hw);
210
211- mutex_unlock(&dev->mt76.mutex);
212-
213 mt7915_update_beacons(dev);
214
215- ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
216- MT7915_WATCHDOG_TIME);
217- if (phy2)
218- ieee80211_queue_delayed_work(ext_phy->hw,
219- &phy2->mt76->mac_work,
220- MT7915_WATCHDOG_TIME);
221-
222- if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
223- mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
224- ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
225-
226 dev_info(dev->mt76.dev,"\n%s L1 SER recovery completed.",
227 wiphy_name(dev->mt76.hw->wiphy));
228 }
229--
2302.18.0
231