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