drm: bridge: adv7511: remove s32 format from i2s capabilities
[drm/drm-misc.git] / drivers / net / wireless / mediatek / mt76 / util.h
blob260965dde94cf7cb7284de18b95acac8b95df503
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
5 */
7 #ifndef __MT76_UTIL_H
8 #define __MT76_UTIL_H
10 #include <linux/skbuff.h>
11 #include <linux/bitops.h>
12 #include <linux/bitfield.h>
13 #include <net/mac80211.h>
15 struct mt76_worker
17 struct task_struct *task;
18 void (*fn)(struct mt76_worker *);
19 unsigned long state;
22 enum {
23 MT76_WORKER_SCHEDULED,
24 MT76_WORKER_RUNNING,
27 #define MT76_INCR(_var, _size) \
28 (_var = (((_var) + 1) % (_size)))
30 int mt76_wcid_alloc(u32 *mask, int size);
32 static inline void
33 mt76_wcid_mask_set(u32 *mask, int idx)
35 mask[idx / 32] |= BIT(idx % 32);
38 static inline void
39 mt76_wcid_mask_clear(u32 *mask, int idx)
41 mask[idx / 32] &= ~BIT(idx % 32);
44 static inline void
45 mt76_skb_set_moredata(struct sk_buff *skb, bool enable)
47 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
49 if (enable)
50 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
51 else
52 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
55 int __mt76_worker_fn(void *ptr);
57 static inline int
58 mt76_worker_setup(struct ieee80211_hw *hw, struct mt76_worker *w,
59 void (*fn)(struct mt76_worker *),
60 const char *name)
62 const char *dev_name = wiphy_name(hw->wiphy);
63 int ret;
65 if (fn)
66 w->fn = fn;
67 w->task = kthread_run(__mt76_worker_fn, w,
68 "mt76-%s %s", name, dev_name);
70 if (IS_ERR(w->task)) {
71 ret = PTR_ERR(w->task);
72 w->task = NULL;
73 return ret;
76 return 0;
79 static inline void mt76_worker_schedule(struct mt76_worker *w)
81 if (!w->task)
82 return;
84 if (!test_and_set_bit(MT76_WORKER_SCHEDULED, &w->state) &&
85 !test_bit(MT76_WORKER_RUNNING, &w->state))
86 wake_up_process(w->task);
89 static inline void mt76_worker_disable(struct mt76_worker *w)
91 if (!w->task)
92 return;
94 kthread_park(w->task);
95 WRITE_ONCE(w->state, 0);
98 static inline void mt76_worker_enable(struct mt76_worker *w)
100 if (!w->task)
101 return;
103 kthread_unpark(w->task);
104 mt76_worker_schedule(w);
107 static inline void mt76_worker_teardown(struct mt76_worker *w)
109 if (!w->task)
110 return;
112 kthread_stop(w->task);
113 w->task = NULL;
116 #endif