linux/drivers/net/wireless/mediatek/mt76/util.h
Felix Fietkau a96fed2825 wifi: mt76: relicense to BSD-3-Clause-Clear
MediaTek has asked to switch from the ISC license to BSD-3-Clause-Clear,
in order to improve clarity and the legal integrity of the code.

The BSD-3-Clause license includes the "no endorsement" clause, which is
important for protecting the reputation of the original authors and
contributors by preventing unauthorized use of their names for endorsement
purposes.

This clause is absent in the BSD-2-Clause license, which is more permissive
but lacks this specific protection.

This change also cleans up the license of some Kconfig/Makefile files,
which were accidentally marked as GPL.

The GPL 2.0 remains in use on mt76x0, as well as two source files in mt7615
for which the license situation still needs to be clarified.

Link: https://patch.msgid.link/20251008104250.46292-2-nbd@nbd.name
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-11-24 14:37:54 +01:00

116 lines
2.1 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause-Clear */
/*
* Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
*/
#ifndef __MT76_UTIL_H
#define __MT76_UTIL_H
#include <linux/skbuff.h>
#include <linux/bitops.h>
#include <linux/bitfield.h>
#include <net/mac80211.h>
struct mt76_worker
{
struct task_struct *task;
void (*fn)(struct mt76_worker *);
unsigned long state;
};
enum {
MT76_WORKER_SCHEDULED,
MT76_WORKER_RUNNING,
};
#define MT76_INCR(_var, _size) \
(_var = (((_var) + 1) % (_size)))
int mt76_wcid_alloc(u32 *mask, int size);
static inline void
mt76_wcid_mask_set(u32 *mask, int idx)
{
mask[idx / 32] |= BIT(idx % 32);
}
static inline void
mt76_wcid_mask_clear(u32 *mask, int idx)
{
mask[idx / 32] &= ~BIT(idx % 32);
}
static inline void
mt76_skb_set_moredata(struct sk_buff *skb, bool enable)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
if (enable)
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
else
hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
}
int __mt76_worker_fn(void *ptr);
static inline int
mt76_worker_setup(struct ieee80211_hw *hw, struct mt76_worker *w,
void (*fn)(struct mt76_worker *),
const char *name)
{
const char *dev_name = wiphy_name(hw->wiphy);
int ret;
if (fn)
w->fn = fn;
w->task = kthread_run(__mt76_worker_fn, w,
"mt76-%s %s", name, dev_name);
if (IS_ERR(w->task)) {
ret = PTR_ERR(w->task);
w->task = NULL;
return ret;
}
return 0;
}
static inline void mt76_worker_schedule(struct mt76_worker *w)
{
if (!w->task)
return;
if (!test_and_set_bit(MT76_WORKER_SCHEDULED, &w->state) &&
!test_bit(MT76_WORKER_RUNNING, &w->state))
wake_up_process(w->task);
}
static inline void mt76_worker_disable(struct mt76_worker *w)
{
if (!w->task)
return;
kthread_park(w->task);
WRITE_ONCE(w->state, 0);
}
static inline void mt76_worker_enable(struct mt76_worker *w)
{
if (!w->task)
return;
kthread_unpark(w->task);
mt76_worker_schedule(w);
}
static inline void mt76_worker_teardown(struct mt76_worker *w)
{
if (!w->task)
return;
kthread_stop(w->task);
w->task = NULL;
}
#endif