treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / mediatek / mt76 / mt76x2 / pci_main.c
blobcfe8905ce73f4de2f470a7881d56f01714e992a7
1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 */
6 #include "mt76x2.h"
7 #include "../mt76x02_mac.h"
9 static int
10 mt76x2_start(struct ieee80211_hw *hw)
12 struct mt76x02_dev *dev = hw->priv;
13 int ret;
15 mt76x02_mac_start(dev);
16 ret = mt76x2_phy_start(dev);
17 if (ret)
18 return ret;
20 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mt76.mac_work,
21 MT_MAC_WORK_INTERVAL);
22 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->wdt_work,
23 MT_WATCHDOG_TIME);
25 set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
26 return 0;
29 static void
30 mt76x2_stop(struct ieee80211_hw *hw)
32 struct mt76x02_dev *dev = hw->priv;
34 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
35 mt76x2_stop_hardware(dev);
38 static int
39 mt76x2_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
41 int ret;
43 cancel_delayed_work_sync(&dev->cal_work);
44 tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
45 tasklet_disable(&dev->dfs_pd.dfs_tasklet);
47 mutex_lock(&dev->mt76.mutex);
48 set_bit(MT76_RESET, &dev->mt76.state);
50 mt76_set_channel(&dev->mt76);
52 mt76x2_mac_stop(dev, true);
53 ret = mt76x2_phy_set_channel(dev, chandef);
55 mt76x02_mac_cc_reset(dev);
56 mt76x02_dfs_init_params(dev);
58 mt76x2_mac_resume(dev);
60 clear_bit(MT76_RESET, &dev->mt76.state);
61 mutex_unlock(&dev->mt76.mutex);
63 tasklet_enable(&dev->dfs_pd.dfs_tasklet);
64 tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
66 mt76_txq_schedule_all(&dev->mt76);
68 return ret;
71 static int
72 mt76x2_config(struct ieee80211_hw *hw, u32 changed)
74 struct mt76x02_dev *dev = hw->priv;
75 int ret = 0;
77 mutex_lock(&dev->mt76.mutex);
79 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
80 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
81 dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
82 else
83 dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
85 mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
88 if (changed & IEEE80211_CONF_CHANGE_POWER) {
89 dev->mt76.txpower_conf = hw->conf.power_level * 2;
91 /* convert to per-chain power for 2x2 devices */
92 dev->mt76.txpower_conf -= 6;
94 if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state)) {
95 mt76x2_phy_set_txpower(dev);
96 mt76x02_tx_set_txpwr_auto(dev, dev->mt76.txpower_conf);
100 mutex_unlock(&dev->mt76.mutex);
102 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
103 ieee80211_stop_queues(hw);
104 ret = mt76x2_set_channel(dev, &hw->conf.chandef);
105 ieee80211_wake_queues(hw);
108 return ret;
111 static void
112 mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
113 u32 queues, bool drop)
117 static int mt76x2_set_antenna(struct ieee80211_hw *hw, u32 tx_ant,
118 u32 rx_ant)
120 struct mt76x02_dev *dev = hw->priv;
122 if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)
123 return -EINVAL;
125 mutex_lock(&dev->mt76.mutex);
127 dev->mt76.chainmask = (tx_ant == 3) ? 0x202 : 0x101;
128 dev->mt76.antenna_mask = tx_ant;
130 mt76_set_stream_caps(&dev->mt76, true);
131 mt76x2_phy_set_antenna(dev);
133 mutex_unlock(&dev->mt76.mutex);
135 return 0;
138 const struct ieee80211_ops mt76x2_ops = {
139 .tx = mt76x02_tx,
140 .start = mt76x2_start,
141 .stop = mt76x2_stop,
142 .add_interface = mt76x02_add_interface,
143 .remove_interface = mt76x02_remove_interface,
144 .config = mt76x2_config,
145 .configure_filter = mt76x02_configure_filter,
146 .bss_info_changed = mt76x02_bss_info_changed,
147 .sta_state = mt76_sta_state,
148 .set_key = mt76x02_set_key,
149 .conf_tx = mt76x02_conf_tx,
150 .sw_scan_start = mt76_sw_scan,
151 .sw_scan_complete = mt76x02_sw_scan_complete,
152 .flush = mt76x2_flush,
153 .ampdu_action = mt76x02_ampdu_action,
154 .get_txpower = mt76_get_txpower,
155 .wake_tx_queue = mt76_wake_tx_queue,
156 .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
157 .release_buffered_frames = mt76_release_buffered_frames,
158 .set_coverage_class = mt76x02_set_coverage_class,
159 .get_survey = mt76_get_survey,
160 .set_tim = mt76_set_tim,
161 .set_antenna = mt76x2_set_antenna,
162 .get_antenna = mt76_get_antenna,
163 .set_rts_threshold = mt76x02_set_rts_threshold,