1*6c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
2*6c92544dSBjoern A. Zeeb /*
3*6c92544dSBjoern A. Zeeb * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4*6c92544dSBjoern A. Zeeb */
5*6c92544dSBjoern A. Zeeb
6*6c92544dSBjoern A. Zeeb #include "mt76x2.h"
7*6c92544dSBjoern A. Zeeb #include "../mt76x02_mac.h"
8*6c92544dSBjoern A. Zeeb
9*6c92544dSBjoern A. Zeeb static int
mt76x2_start(struct ieee80211_hw * hw)10*6c92544dSBjoern A. Zeeb mt76x2_start(struct ieee80211_hw *hw)
11*6c92544dSBjoern A. Zeeb {
12*6c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
13*6c92544dSBjoern A. Zeeb
14*6c92544dSBjoern A. Zeeb mt76x02_mac_start(dev);
15*6c92544dSBjoern A. Zeeb mt76x2_phy_start(dev);
16*6c92544dSBjoern A. Zeeb
17*6c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
18*6c92544dSBjoern A. Zeeb MT_MAC_WORK_INTERVAL);
19*6c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(mt76_hw(dev), &dev->wdt_work,
20*6c92544dSBjoern A. Zeeb MT_WATCHDOG_TIME);
21*6c92544dSBjoern A. Zeeb
22*6c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
23*6c92544dSBjoern A. Zeeb return 0;
24*6c92544dSBjoern A. Zeeb }
25*6c92544dSBjoern A. Zeeb
26*6c92544dSBjoern A. Zeeb static void
mt76x2_stop(struct ieee80211_hw * hw)27*6c92544dSBjoern A. Zeeb mt76x2_stop(struct ieee80211_hw *hw)
28*6c92544dSBjoern A. Zeeb {
29*6c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
30*6c92544dSBjoern A. Zeeb
31*6c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
32*6c92544dSBjoern A. Zeeb mt76x2_stop_hardware(dev);
33*6c92544dSBjoern A. Zeeb }
34*6c92544dSBjoern A. Zeeb
35*6c92544dSBjoern A. Zeeb static void
mt76x2_set_channel(struct mt76x02_dev * dev,struct cfg80211_chan_def * chandef)36*6c92544dSBjoern A. Zeeb mt76x2_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
37*6c92544dSBjoern A. Zeeb {
38*6c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->cal_work);
39*6c92544dSBjoern A. Zeeb tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
40*6c92544dSBjoern A. Zeeb tasklet_disable(&dev->dfs_pd.dfs_tasklet);
41*6c92544dSBjoern A. Zeeb
42*6c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
43*6c92544dSBjoern A. Zeeb set_bit(MT76_RESET, &dev->mphy.state);
44*6c92544dSBjoern A. Zeeb
45*6c92544dSBjoern A. Zeeb mt76_set_channel(&dev->mphy);
46*6c92544dSBjoern A. Zeeb
47*6c92544dSBjoern A. Zeeb mt76x2_mac_stop(dev, true);
48*6c92544dSBjoern A. Zeeb mt76x2_phy_set_channel(dev, chandef);
49*6c92544dSBjoern A. Zeeb
50*6c92544dSBjoern A. Zeeb mt76x02_mac_cc_reset(dev);
51*6c92544dSBjoern A. Zeeb mt76x02_dfs_init_params(dev);
52*6c92544dSBjoern A. Zeeb
53*6c92544dSBjoern A. Zeeb mt76x2_mac_resume(dev);
54*6c92544dSBjoern A. Zeeb
55*6c92544dSBjoern A. Zeeb clear_bit(MT76_RESET, &dev->mphy.state);
56*6c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
57*6c92544dSBjoern A. Zeeb
58*6c92544dSBjoern A. Zeeb tasklet_enable(&dev->dfs_pd.dfs_tasklet);
59*6c92544dSBjoern A. Zeeb tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
60*6c92544dSBjoern A. Zeeb
61*6c92544dSBjoern A. Zeeb mt76_txq_schedule_all(&dev->mphy);
62*6c92544dSBjoern A. Zeeb }
63*6c92544dSBjoern A. Zeeb
64*6c92544dSBjoern A. Zeeb static int
mt76x2_config(struct ieee80211_hw * hw,u32 changed)65*6c92544dSBjoern A. Zeeb mt76x2_config(struct ieee80211_hw *hw, u32 changed)
66*6c92544dSBjoern A. Zeeb {
67*6c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
68*6c92544dSBjoern A. Zeeb
69*6c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
70*6c92544dSBjoern A. Zeeb
71*6c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
72*6c92544dSBjoern A. Zeeb if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
73*6c92544dSBjoern A. Zeeb dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
74*6c92544dSBjoern A. Zeeb else
75*6c92544dSBjoern A. Zeeb dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
76*6c92544dSBjoern A. Zeeb
77*6c92544dSBjoern A. Zeeb mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
78*6c92544dSBjoern A. Zeeb }
79*6c92544dSBjoern A. Zeeb
80*6c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_POWER) {
81*6c92544dSBjoern A. Zeeb struct mt76_phy *mphy = &dev->mphy;
82*6c92544dSBjoern A. Zeeb
83*6c92544dSBjoern A. Zeeb dev->txpower_conf = hw->conf.power_level * 2;
84*6c92544dSBjoern A. Zeeb dev->txpower_conf = mt76_get_sar_power(mphy,
85*6c92544dSBjoern A. Zeeb mphy->chandef.chan,
86*6c92544dSBjoern A. Zeeb dev->txpower_conf);
87*6c92544dSBjoern A. Zeeb /* convert to per-chain power for 2x2 devices */
88*6c92544dSBjoern A. Zeeb dev->txpower_conf -= 6;
89*6c92544dSBjoern A. Zeeb
90*6c92544dSBjoern A. Zeeb if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) {
91*6c92544dSBjoern A. Zeeb mt76x2_phy_set_txpower(dev);
92*6c92544dSBjoern A. Zeeb mt76x02_tx_set_txpwr_auto(dev, dev->txpower_conf);
93*6c92544dSBjoern A. Zeeb }
94*6c92544dSBjoern A. Zeeb }
95*6c92544dSBjoern A. Zeeb
96*6c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
97*6c92544dSBjoern A. Zeeb
98*6c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
99*6c92544dSBjoern A. Zeeb ieee80211_stop_queues(hw);
100*6c92544dSBjoern A. Zeeb mt76x2_set_channel(dev, &hw->conf.chandef);
101*6c92544dSBjoern A. Zeeb ieee80211_wake_queues(hw);
102*6c92544dSBjoern A. Zeeb }
103*6c92544dSBjoern A. Zeeb
104*6c92544dSBjoern A. Zeeb return 0;
105*6c92544dSBjoern A. Zeeb }
106*6c92544dSBjoern A. Zeeb
107*6c92544dSBjoern A. Zeeb static void
mt76x2_flush(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 queues,bool drop)108*6c92544dSBjoern A. Zeeb mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
109*6c92544dSBjoern A. Zeeb u32 queues, bool drop)
110*6c92544dSBjoern A. Zeeb {
111*6c92544dSBjoern A. Zeeb }
112*6c92544dSBjoern A. Zeeb
mt76x2_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)113*6c92544dSBjoern A. Zeeb static int mt76x2_set_antenna(struct ieee80211_hw *hw, u32 tx_ant,
114*6c92544dSBjoern A. Zeeb u32 rx_ant)
115*6c92544dSBjoern A. Zeeb {
116*6c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
117*6c92544dSBjoern A. Zeeb
118*6c92544dSBjoern A. Zeeb if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)
119*6c92544dSBjoern A. Zeeb return -EINVAL;
120*6c92544dSBjoern A. Zeeb
121*6c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
122*6c92544dSBjoern A. Zeeb
123*6c92544dSBjoern A. Zeeb dev->mphy.chainmask = (tx_ant == 3) ? 0x202 : 0x101;
124*6c92544dSBjoern A. Zeeb dev->mphy.antenna_mask = tx_ant;
125*6c92544dSBjoern A. Zeeb
126*6c92544dSBjoern A. Zeeb mt76_set_stream_caps(&dev->mphy, true);
127*6c92544dSBjoern A. Zeeb mt76x2_phy_set_antenna(dev);
128*6c92544dSBjoern A. Zeeb
129*6c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
130*6c92544dSBjoern A. Zeeb
131*6c92544dSBjoern A. Zeeb return 0;
132*6c92544dSBjoern A. Zeeb }
133*6c92544dSBjoern A. Zeeb
134*6c92544dSBjoern A. Zeeb const struct ieee80211_ops mt76x2_ops = {
135*6c92544dSBjoern A. Zeeb .tx = mt76x02_tx,
136*6c92544dSBjoern A. Zeeb .start = mt76x2_start,
137*6c92544dSBjoern A. Zeeb .stop = mt76x2_stop,
138*6c92544dSBjoern A. Zeeb .add_interface = mt76x02_add_interface,
139*6c92544dSBjoern A. Zeeb .remove_interface = mt76x02_remove_interface,
140*6c92544dSBjoern A. Zeeb .config = mt76x2_config,
141*6c92544dSBjoern A. Zeeb .configure_filter = mt76x02_configure_filter,
142*6c92544dSBjoern A. Zeeb .bss_info_changed = mt76x02_bss_info_changed,
143*6c92544dSBjoern A. Zeeb .sta_state = mt76_sta_state,
144*6c92544dSBjoern A. Zeeb .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
145*6c92544dSBjoern A. Zeeb .set_key = mt76x02_set_key,
146*6c92544dSBjoern A. Zeeb .conf_tx = mt76x02_conf_tx,
147*6c92544dSBjoern A. Zeeb .sw_scan_start = mt76_sw_scan,
148*6c92544dSBjoern A. Zeeb .sw_scan_complete = mt76x02_sw_scan_complete,
149*6c92544dSBjoern A. Zeeb .flush = mt76x2_flush,
150*6c92544dSBjoern A. Zeeb .ampdu_action = mt76x02_ampdu_action,
151*6c92544dSBjoern A. Zeeb .get_txpower = mt76_get_txpower,
152*6c92544dSBjoern A. Zeeb .wake_tx_queue = mt76_wake_tx_queue,
153*6c92544dSBjoern A. Zeeb .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
154*6c92544dSBjoern A. Zeeb .release_buffered_frames = mt76_release_buffered_frames,
155*6c92544dSBjoern A. Zeeb .set_coverage_class = mt76x02_set_coverage_class,
156*6c92544dSBjoern A. Zeeb .get_survey = mt76_get_survey,
157*6c92544dSBjoern A. Zeeb .set_tim = mt76_set_tim,
158*6c92544dSBjoern A. Zeeb .set_antenna = mt76x2_set_antenna,
159*6c92544dSBjoern A. Zeeb .get_antenna = mt76_get_antenna,
160*6c92544dSBjoern A. Zeeb .set_rts_threshold = mt76x02_set_rts_threshold,
161*6c92544dSBjoern A. Zeeb .reconfig_complete = mt76x02_reconfig_complete,
162*6c92544dSBjoern A. Zeeb .set_sar_specs = mt76x2_set_sar_specs,
163*6c92544dSBjoern A. Zeeb };
164*6c92544dSBjoern A. Zeeb
165