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  */
6 
7 #ifndef __MT76_UTIL_H
8 #define __MT76_UTIL_H
9 
10 #include <linux/skbuff.h>
11 #include <linux/bitops.h>
12 #include <linux/bitfield.h>
13 
14 #define MT76_INCR(_var, _size) \
15 	(_var = (((_var) + 1) % (_size)))
16 
17 int mt76_wcid_alloc(unsigned long *mask, int size);
18 
19 static inline bool
20 mt76_wcid_mask_test(unsigned long *mask, int idx)
21 {
22 	return mask[idx / BITS_PER_LONG] & BIT(idx % BITS_PER_LONG);
23 }
24 
25 static inline void
26 mt76_wcid_mask_set(unsigned long *mask, int idx)
27 {
28 	mask[idx / BITS_PER_LONG] |= BIT(idx % BITS_PER_LONG);
29 }
30 
31 static inline void
32 mt76_wcid_mask_clear(unsigned long *mask, int idx)
33 {
34 	mask[idx / BITS_PER_LONG] &= ~BIT(idx % BITS_PER_LONG);
35 }
36 
37 static inline void
38 mt76_skb_set_moredata(struct sk_buff *skb, bool enable)
39 {
40 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
41 
42 	if (enable)
43 		hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
44 	else
45 		hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
46 }
47 
48 #endif
49