1 // SPDX-License-Identifier: ISC
6 #include <linux/module.h>
9 bool __mt76_poll(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
16 cur = __mt76_rr(dev, offset) & mask;
21 } while (timeout-- > 0);
25 EXPORT_SYMBOL_GPL(__mt76_poll);
27 bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
28 int timeout, int tick)
34 cur = __mt76_rr(dev, offset) & mask;
38 usleep_range(1000 * tick, 2000 * tick);
39 } while (timeout-- > 0);
43 EXPORT_SYMBOL_GPL(____mt76_poll_msec);
45 int mt76_wcid_alloc(u32 *mask, int size)
49 for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
65 EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
67 int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx)
69 struct mt76_wcid *wcid;
70 int i, j, min_rssi = 0;
76 for (i = 0; i < ARRAY_SIZE(dev->wcid_mask); i++) {
77 u32 mask = dev->wcid_mask[i];
82 for (j = i * 32; mask; j++, mask >>= 1) {
86 wcid = rcu_dereference(dev->wcid[j]);
87 if (!wcid || wcid->phy_idx != phy_idx)
90 spin_lock(&dev->rx_lock);
91 if (wcid->inactive_count++ < 5)
92 cur_rssi = -ewma_signal_read(&wcid->rssi);
95 spin_unlock(&dev->rx_lock);
97 if (cur_rssi < min_rssi)
107 EXPORT_SYMBOL_GPL(mt76_get_min_avg_rssi);
109 int __mt76_worker_fn(void *ptr)
111 struct mt76_worker *w = ptr;
113 while (!kthread_should_stop()) {
114 set_current_state(TASK_INTERRUPTIBLE);
116 if (kthread_should_park()) {
121 if (!test_and_clear_bit(MT76_WORKER_SCHEDULED, &w->state)) {
126 set_bit(MT76_WORKER_RUNNING, &w->state);
127 set_current_state(TASK_RUNNING);
130 clear_bit(MT76_WORKER_RUNNING, &w->state);
135 EXPORT_SYMBOL_GPL(__mt76_worker_fn);
137 MODULE_DESCRIPTION("MediaTek MT76x helpers");
138 MODULE_LICENSE("Dual BSD/GPL");