mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
This is a set of updates of the mt76 driver based on wireless-testing (wt-2023-05-11) 711dca0ca3d77414f8f346e564e9c8640147f40d (after v6.4-rc1), This adds support for mt7996 as well. (wt-2023-06-09) 7bd20e011626ccc3ad53e57873452b1716fcfaaa (after v6.4-rc5), (wt-2023-07-24) 62e409149b62a285e89018e49b2e115757fb9022 (after v6.5-rc3), (wt-2023-08-06) 2a220a15be657a24868368892e3e2caba2115283 (after v6.5-rc4). The current version of LinuxKPI lacks support for "page pool" which needs enhancing and updating a decade or so old shortcut mapping struct page directly to struct vm_page. MFC after: 20 days
150 lines
2.7 KiB
C
150 lines
2.7 KiB
C
// SPDX-License-Identifier: ISC
|
|
/*
|
|
* Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#if defined(__FreeBSD__)
|
|
#include <linux/delay.h>
|
|
#include <linux/kthread.h>
|
|
#endif
|
|
#include "mt76.h"
|
|
|
|
bool __mt76_poll(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
|
|
int timeout)
|
|
{
|
|
u32 cur;
|
|
|
|
timeout /= 10;
|
|
do {
|
|
cur = __mt76_rr(dev, offset) & mask;
|
|
if (cur == val)
|
|
return true;
|
|
|
|
udelay(10);
|
|
} while (timeout-- > 0);
|
|
|
|
return false;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__mt76_poll);
|
|
|
|
bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
|
|
int timeout, int tick)
|
|
{
|
|
u32 cur;
|
|
|
|
timeout /= tick;
|
|
do {
|
|
cur = __mt76_rr(dev, offset) & mask;
|
|
if (cur == val)
|
|
return true;
|
|
|
|
usleep_range(1000 * tick, 2000 * tick);
|
|
} while (timeout-- > 0);
|
|
|
|
return false;
|
|
}
|
|
EXPORT_SYMBOL_GPL(____mt76_poll_msec);
|
|
|
|
int mt76_wcid_alloc(u32 *mask, int size)
|
|
{
|
|
int i, idx = 0, cur;
|
|
|
|
for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
|
|
idx = ffs(~mask[i]);
|
|
if (!idx)
|
|
continue;
|
|
|
|
idx--;
|
|
cur = i * 32 + idx;
|
|
if (cur >= size)
|
|
break;
|
|
|
|
mask[i] |= BIT(idx);
|
|
return cur;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
|
|
|
|
int mt76_get_min_avg_rssi(struct mt76_dev *dev, bool ext_phy)
|
|
{
|
|
struct mt76_wcid *wcid;
|
|
int i, j, min_rssi = 0;
|
|
s8 cur_rssi;
|
|
|
|
local_bh_disable();
|
|
rcu_read_lock();
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->wcid_mask); i++) {
|
|
u32 mask = dev->wcid_mask[i];
|
|
u32 phy_mask = dev->wcid_phy_mask[i];
|
|
|
|
if (!mask)
|
|
continue;
|
|
|
|
for (j = i * 32; mask; j++, mask >>= 1, phy_mask >>= 1) {
|
|
if (!(mask & 1))
|
|
continue;
|
|
|
|
if (!!(phy_mask & 1) != ext_phy)
|
|
continue;
|
|
|
|
wcid = rcu_dereference(dev->wcid[j]);
|
|
if (!wcid)
|
|
continue;
|
|
|
|
spin_lock(&dev->rx_lock);
|
|
if (wcid->inactive_count++ < 5)
|
|
cur_rssi = -ewma_signal_read(&wcid->rssi);
|
|
else
|
|
cur_rssi = 0;
|
|
spin_unlock(&dev->rx_lock);
|
|
|
|
if (cur_rssi < min_rssi)
|
|
min_rssi = cur_rssi;
|
|
}
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
local_bh_enable();
|
|
|
|
return min_rssi;
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_get_min_avg_rssi);
|
|
|
|
int __mt76_worker_fn(void *ptr)
|
|
{
|
|
struct mt76_worker *w = ptr;
|
|
|
|
while (!kthread_should_stop()) {
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
if (kthread_should_park()) {
|
|
kthread_parkme();
|
|
continue;
|
|
}
|
|
|
|
if (!test_and_clear_bit(MT76_WORKER_SCHEDULED, &w->state)) {
|
|
schedule();
|
|
continue;
|
|
}
|
|
|
|
set_bit(MT76_WORKER_RUNNING, &w->state);
|
|
set_current_state(TASK_RUNNING);
|
|
w->fn(w);
|
|
cond_resched();
|
|
clear_bit(MT76_WORKER_RUNNING, &w->state);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__mt76_worker_fn);
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
#if defined(__FreeBSD__)
|
|
MODULE_VERSION(mt76_core, 1);
|
|
MODULE_DEPEND(mt76_core, linuxkpi, 1, 1, 1);
|
|
MODULE_DEPEND(mt76_core, linuxkpi_wlan, 1, 1, 1);
|
|
#endif
|