treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174
[linux-2.6-block.git] / drivers / net / wireless / mediatek / mt76 / mt76x0 / main.c
CommitLineData
1802d0be 1// SPDX-License-Identifier: GPL-2.0-only
95e44409
SG
2/*
3 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
5 * Copyright (C) 2018 Stanislaw Gruszka <stf_xl@wp.pl>
95e44409
SG
6 */
7
95e44409 8#include <linux/etherdevice.h>
7a07adcd 9#include "mt76x0.h"
95e44409 10
bbd10586
LB
11static int
12mt76x0_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
13{
14 int ret;
15
16 cancel_delayed_work_sync(&dev->cal_work);
c004b881
SG
17 dev->beacon_ops->pre_tbtt_enable(dev, false);
18 if (mt76_is_mmio(dev))
801ccc8a 19 tasklet_disable(&dev->dfs_pd.dfs_tasklet);
bbd10586
LB
20
21 mt76_set_channel(&dev->mt76);
22 ret = mt76x0_phy_set_channel(dev, chandef);
62503186
LB
23
24 /* channel cycle counters read-and-clear */
25 mt76_rr(dev, MT_CH_IDLE);
26 mt76_rr(dev, MT_CH_BUSY);
27
4606a26c
FF
28 mt76x02_edcca_init(dev, true);
29
801ccc8a
LB
30 if (mt76_is_mmio(dev)) {
31 mt76x02_dfs_init_params(dev);
801ccc8a
LB
32 tasklet_enable(&dev->dfs_pd.dfs_tasklet);
33 }
c004b881
SG
34 dev->beacon_ops->pre_tbtt_enable(dev, true);
35
bbd10586
LB
36 mt76_txq_schedule_all(&dev->mt76);
37
38 return ret;
39}
40
b11e1969 41int mt76x0_config(struct ieee80211_hw *hw, u32 changed)
95e44409 42{
b2d871c0 43 struct mt76x02_dev *dev = hw->priv;
95e44409
SG
44 int ret = 0;
45
108a4861 46 mutex_lock(&dev->mt76.mutex);
95e44409
SG
47
48 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
49 ieee80211_stop_queues(hw);
bbd10586 50 ret = mt76x0_set_channel(dev, &hw->conf.chandef);
95e44409
SG
51 ieee80211_wake_queues(hw);
52 }
53
1f4db1fd
LB
54 if (changed & IEEE80211_CONF_CHANGE_POWER) {
55 dev->mt76.txpower_conf = hw->conf.power_level * 2;
56
57 if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state))
58 mt76x0_phy_set_txpower(dev);
59 }
60
a31821ab
LB
61 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
62 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
63 dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
64 else
65 dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
66
67 mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
68 }
69
108a4861 70 mutex_unlock(&dev->mt76.mutex);
95e44409
SG
71
72 return ret;
73}
b11e1969 74EXPORT_SYMBOL_GPL(mt76x0_config);