summaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/mediatek/mt76/mcu.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2020-09-30 04:35:11 +0200
committerFelix Fietkau <nbd@nbd.name>2020-12-04 13:46:15 +0100
commite452c6eb55fbfd21eef6e95f63a0265655d5b677 (patch)
treebf4d4b241691f580790abc6363eeb7a713055312 /drivers/net/wireless/mediatek/mt76/mcu.c
parentmt76: move mcu timeout handling to .mcu_parse_response (diff)
downloadlinux-e452c6eb55fbfd21eef6e95f63a0265655d5b677.tar.xz
linux-e452c6eb55fbfd21eef6e95f63a0265655d5b677.zip
mt76: move waiting and locking out of mcu_ops->mcu_skb_send_msg
This removes some code duplication and prepares the code for making the MCU API more flexible Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'drivers/net/wireless/mediatek/mt76/mcu.c')
-rw-r--r--drivers/net/wireless/mediatek/mt76/mcu.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/mcu.c b/drivers/net/wireless/mediatek/mt76/mcu.c
index ade61a5334c6..118272cabe16 100644
--- a/drivers/net/wireless/mediatek/mt76/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mcu.c
@@ -50,3 +50,35 @@ void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb)
wake_up(&dev->mcu.wait);
}
EXPORT_SYMBOL_GPL(mt76_mcu_rx_event);
+
+int mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
+ int cmd, bool wait_resp)
+{
+ unsigned long expires;
+ int ret, seq;
+
+ mutex_lock(&dev->mcu.mutex);
+
+ ret = dev->mcu_ops->mcu_skb_send_msg(dev, skb, cmd, &seq);
+ if (ret < 0)
+ goto out;
+
+ if (!wait_resp) {
+ ret = 0;
+ goto out;
+ }
+
+ expires = jiffies + dev->mcu.timeout;
+
+ do {
+ skb = mt76_mcu_get_response(dev, expires);
+ ret = dev->mcu_ops->mcu_parse_response(dev, cmd, skb, seq);
+ dev_kfree_skb(skb);
+ } while (ret == -EAGAIN);
+
+out:
+ mutex_unlock(&dev->mcu.mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(mt76_mcu_skb_send_msg);