gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / wireless / mediatek / mt76 / mcu.c
blob4048f446e3eee23a2ba574471ec0189ace9c91f1
1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (C) 2019 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
4 */
6 #include "mt76.h"
8 struct sk_buff *
9 mt76_mcu_msg_alloc(const void *data, int head_len,
10 int data_len, int tail_len)
12 int length = head_len + data_len + tail_len;
13 struct sk_buff *skb;
15 skb = alloc_skb(length, GFP_KERNEL);
16 if (!skb)
17 return NULL;
19 memset(skb->head, 0, length);
20 skb_reserve(skb, head_len);
22 if (data && data_len)
23 skb_put_data(skb, data, data_len);
25 return skb;
27 EXPORT_SYMBOL_GPL(mt76_mcu_msg_alloc);
29 struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev,
30 unsigned long expires)
32 unsigned long timeout;
34 if (!time_is_after_jiffies(expires))
35 return NULL;
37 timeout = expires - jiffies;
38 wait_event_timeout(dev->mcu.wait,
39 (!skb_queue_empty(&dev->mcu.res_q) ||
40 test_bit(MT76_MCU_RESET, &dev->phy.state)),
41 timeout);
42 return skb_dequeue(&dev->mcu.res_q);
44 EXPORT_SYMBOL_GPL(mt76_mcu_get_response);
46 void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb)
48 skb_queue_tail(&dev->mcu.res_q, skb);
49 wake_up(&dev->mcu.wait);
51 EXPORT_SYMBOL_GPL(mt76_mcu_rx_event);