2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/module.h>
20 bool __mt76_poll(struct mt76_dev
*dev
, u32 offset
, u32 mask
, u32 val
,
27 cur
= dev
->bus
->rr(dev
, offset
) & mask
;
32 } while (timeout
-- > 0);
36 EXPORT_SYMBOL_GPL(__mt76_poll
);
38 bool __mt76_poll_msec(struct mt76_dev
*dev
, u32 offset
, u32 mask
, u32 val
,
45 cur
= dev
->bus
->rr(dev
, offset
) & mask
;
49 usleep_range(10000, 20000);
50 } while (timeout
-- > 0);
54 EXPORT_SYMBOL_GPL(__mt76_poll_msec
);
56 int mt76_wcid_alloc(unsigned long *mask
, int size
)
60 for (i
= 0; i
< size
/ BITS_PER_LONG
; i
++) {
66 cur
= i
* BITS_PER_LONG
+ idx
;
76 EXPORT_SYMBOL_GPL(mt76_wcid_alloc
);
78 int mt76_get_min_avg_rssi(struct mt76_dev
*dev
)
80 struct mt76_wcid
*wcid
;
81 int i
, j
, min_rssi
= 0;
87 for (i
= 0; i
< ARRAY_SIZE(dev
->wcid_mask
); i
++) {
88 unsigned long mask
= dev
->wcid_mask
[i
];
93 for (j
= i
* BITS_PER_LONG
; mask
; j
++, mask
>>= 1) {
97 wcid
= rcu_dereference(dev
->wcid
[j
]);
101 spin_lock(&dev
->rx_lock
);
102 if (wcid
->inactive_count
++ < 5)
103 cur_rssi
= -ewma_signal_read(&wcid
->rssi
);
106 spin_unlock(&dev
->rx_lock
);
108 if (cur_rssi
< min_rssi
)
118 EXPORT_SYMBOL_GPL(mt76_get_min_avg_rssi
);
120 MODULE_LICENSE("Dual BSD/GPL");