1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
10 #include <linux/skbuff.h>
11 #include <linux/bitops.h>
12 #include <linux/bitfield.h>
13 #include <net/mac80211.h>
17 struct task_struct
*task
;
18 void (*fn
)(struct mt76_worker
*);
23 MT76_WORKER_SCHEDULED
,
27 #define MT76_INCR(_var, _size) \
28 (_var = (((_var) + 1) % (_size)))
30 int mt76_wcid_alloc(u32
*mask
, int size
);
33 mt76_wcid_mask_set(u32
*mask
, int idx
)
35 mask
[idx
/ 32] |= BIT(idx
% 32);
39 mt76_wcid_mask_clear(u32
*mask
, int idx
)
41 mask
[idx
/ 32] &= ~BIT(idx
% 32);
45 mt76_skb_set_moredata(struct sk_buff
*skb
, bool enable
)
47 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
50 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
52 hdr
->frame_control
&= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
55 int __mt76_worker_fn(void *ptr
);
58 mt76_worker_setup(struct ieee80211_hw
*hw
, struct mt76_worker
*w
,
59 void (*fn
)(struct mt76_worker
*),
62 const char *dev_name
= wiphy_name(hw
->wiphy
);
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
);
79 static inline void mt76_worker_schedule(struct mt76_worker
*w
)
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
)
94 kthread_park(w
->task
);
95 WRITE_ONCE(w
->state
, 0);
98 static inline void mt76_worker_enable(struct mt76_worker
*w
)
103 kthread_unpark(w
->task
);
104 mt76_worker_schedule(w
);
107 static inline void mt76_worker_teardown(struct mt76_worker
*w
)
112 kthread_stop(w
->task
);