Skip to content

Commit f4fdd77

Browse files
committed
wifi: mt76: partially move channel change code to core
This allows the core code to change the channel. Code deduplication and preparation for adding scanning code to the core. Link: https://patch.msgid.link/20240828063422.44813-1-nbd@nbd.name Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent e43b87f commit f4fdd77

File tree

39 files changed

+116
-162
lines changed

39 files changed

+116
-162
lines changed

drivers/net/wireless/mediatek/mt76/mac80211.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,13 +929,19 @@ void mt76_update_survey(struct mt76_phy *phy)
929929
}
930930
EXPORT_SYMBOL_GPL(mt76_update_survey);
931931

932-
void mt76_set_channel(struct mt76_phy *phy)
932+
int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,
933+
bool offchannel)
933934
{
934935
struct mt76_dev *dev = phy->dev;
935-
struct ieee80211_hw *hw = phy->hw;
936-
struct cfg80211_chan_def *chandef = &hw->conf.chandef;
937-
bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL;
938936
int timeout = HZ / 5;
937+
int ret;
938+
939+
cancel_delayed_work_sync(&phy->mac_work);
940+
941+
mutex_lock(&dev->mutex);
942+
set_bit(MT76_RESET, &phy->state);
943+
944+
ieee80211_stop_queues(phy->hw);
939945

940946
wait_event_timeout(dev->tx_wait, !mt76_has_tx_pending(phy), timeout);
941947
mt76_update_survey(phy);
@@ -946,14 +952,35 @@ void mt76_set_channel(struct mt76_phy *phy)
946952

947953
phy->chandef = *chandef;
948954
phy->chan_state = mt76_channel_state(phy, chandef->chan);
955+
phy->offchannel = offchannel;
949956

950957
if (!offchannel)
951958
phy->main_chan = chandef->chan;
952959

953960
if (chandef->chan != phy->main_chan)
954961
memset(phy->chan_state, 0, sizeof(*phy->chan_state));
962+
963+
ret = dev->drv->set_channel(phy);
964+
965+
clear_bit(MT76_RESET, &phy->state);
966+
ieee80211_wake_queues(phy->hw);
967+
968+
mt76_worker_schedule(&dev->tx_worker);
969+
970+
mutex_unlock(&dev->mutex);
971+
972+
return ret;
973+
}
974+
975+
int mt76_update_channel(struct mt76_phy *phy)
976+
{
977+
struct ieee80211_hw *hw = phy->hw;
978+
struct cfg80211_chan_def *chandef = &hw->conf.chandef;
979+
bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL;
980+
981+
return mt76_set_channel(phy, chandef, offchannel);
955982
}
956-
EXPORT_SYMBOL_GPL(mt76_set_channel);
983+
EXPORT_SYMBOL_GPL(mt76_update_channel);
957984

958985
int mt76_get_survey(struct ieee80211_hw *hw, int idx,
959986
struct survey_info *survey)

drivers/net/wireless/mediatek/mt76/mt76.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ struct mt76_driver_ops {
487487
u8 mcs_rates;
488488

489489
void (*update_survey)(struct mt76_phy *phy);
490+
int (*set_channel)(struct mt76_phy *phy);
490491

491492
int (*tx_prepare_skb)(struct mt76_dev *dev, void *txwi_ptr,
492493
enum mt76_txq_id qid, struct mt76_wcid *wcid,
@@ -768,6 +769,7 @@ struct mt76_phy {
768769

769770
struct cfg80211_chan_def chandef;
770771
struct ieee80211_channel *main_chan;
772+
bool offchannel;
771773

772774
struct mt76_channel_state *chan_state;
773775
enum mt76_dfs_state dfs_state;
@@ -1370,7 +1372,7 @@ void mt76_release_buffered_frames(struct ieee80211_hw *hw,
13701372
enum ieee80211_frame_release_type reason,
13711373
bool more_data);
13721374
bool mt76_has_tx_pending(struct mt76_phy *phy);
1373-
void mt76_set_channel(struct mt76_phy *phy);
1375+
int mt76_update_channel(struct mt76_phy *phy);
13741376
void mt76_update_survey(struct mt76_phy *phy);
13751377
void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time);
13761378
int mt76_get_survey(struct ieee80211_hw *hw, int idx,
@@ -1484,6 +1486,8 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames);
14841486
void mt76_testmode_tx_pending(struct mt76_phy *phy);
14851487
void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q,
14861488
struct mt76_queue_entry *e);
1489+
int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,
1490+
bool offchannel);
14871491

14881492
/* usb */
14891493
static inline bool mt76u_urb_error(struct urb *urb)

drivers/net/wireless/mediatek/mt76/mt7603/beacon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void mt7603_pre_tbtt_tasklet(struct tasklet_struct *t)
107107
struct sk_buff *skb;
108108
int i, nframes;
109109

110-
if (mt76_hw(dev)->conf.flags & IEEE80211_CONF_OFFCHANNEL)
110+
if (dev->mphy.offchannel)
111111
return;
112112

113113
data.dev = dev;

drivers/net/wireless/mediatek/mt76/mt7603/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const struct mt76_driver_ops mt7603_drv_ops = {
1818
.sta_assoc = mt7603_sta_assoc,
1919
.sta_remove = mt7603_sta_remove,
2020
.update_survey = mt7603_update_channel,
21+
.set_channel = mt7603_set_channel,
2122
};
2223

2324
static void

drivers/net/wireless/mediatek/mt76/mt7603/main.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,30 +133,24 @@ void mt7603_init_edcca(struct mt7603_dev *dev)
133133
mt7603_edcca_set_strict(dev, false);
134134
}
135135

136-
static int
137-
mt7603_set_channel(struct ieee80211_hw *hw, struct cfg80211_chan_def *def)
136+
int mt7603_set_channel(struct mt76_phy *mphy)
138137
{
139-
struct mt7603_dev *dev = hw->priv;
138+
struct mt7603_dev *dev = container_of(mphy->dev, struct mt7603_dev, mt76);
139+
struct cfg80211_chan_def *def = &mphy->chandef;
140+
140141
u8 *rssi_data = (u8 *)dev->mt76.eeprom.data;
141142
int idx, ret;
142143
u8 bw = MT_BW_20;
143144
bool failed = false;
144145

145-
ieee80211_stop_queues(hw);
146-
cancel_delayed_work_sync(&dev->mphy.mac_work);
147146
tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
148147

149-
mutex_lock(&dev->mt76.mutex);
150-
set_bit(MT76_RESET, &dev->mphy.state);
151-
152148
mt7603_beacon_set_timer(dev, -1, 0);
153-
mt76_set_channel(&dev->mphy);
154149
mt7603_mac_stop(dev);
155150

156151
if (def->width == NL80211_CHAN_WIDTH_40)
157152
bw = MT_BW_40;
158153

159-
dev->mphy.chandef = *def;
160154
mt76_rmw_field(dev, MT_AGG_BWCR, MT_AGG_BWCR_BW, bw);
161155
ret = mt7603_mcu_set_channel(dev);
162156
if (ret) {
@@ -180,10 +174,6 @@ mt7603_set_channel(struct ieee80211_hw *hw, struct cfg80211_chan_def *def)
180174
mt7603_mac_set_timing(dev);
181175
mt7603_mac_start(dev);
182176

183-
clear_bit(MT76_RESET, &dev->mphy.state);
184-
185-
mt76_txq_schedule_all(&dev->mphy);
186-
187177
ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
188178
msecs_to_jiffies(MT7603_WATCHDOG_TIME));
189179

@@ -199,17 +189,14 @@ mt7603_set_channel(struct ieee80211_hw *hw, struct cfg80211_chan_def *def)
199189
mt7603_init_edcca(dev);
200190

201191
out:
202-
if (!(mt76_hw(dev)->conf.flags & IEEE80211_CONF_OFFCHANNEL))
192+
if (!mphy->offchannel)
203193
mt7603_beacon_set_timer(dev, -1, dev->mt76.beacon_int);
204-
mutex_unlock(&dev->mt76.mutex);
205194

206195
tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
207196

208197
if (failed)
209198
mt7603_mac_work(&dev->mphy.mac_work.work);
210199

211-
ieee80211_wake_queues(hw);
212-
213200
return ret;
214201
}
215202

@@ -227,7 +214,7 @@ static int mt7603_set_sar_specs(struct ieee80211_hw *hw,
227214
if (err)
228215
return err;
229216

230-
return mt7603_set_channel(hw, &mphy->chandef);
217+
return mt76_update_channel(mphy);
231218
}
232219

233220
static int
@@ -238,7 +225,7 @@ mt7603_config(struct ieee80211_hw *hw, u32 changed)
238225

239226
if (changed & (IEEE80211_CONF_CHANGE_CHANNEL |
240227
IEEE80211_CONF_CHANGE_POWER))
241-
ret = mt7603_set_channel(hw, &hw->conf.chandef);
228+
ret = mt76_update_channel(&dev->mphy);
242229

243230
if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
244231
mutex_lock(&dev->mt76.mutex);

drivers/net/wireless/mediatek/mt76/mt7603/mt7603.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ void mt7603_mac_sta_poll(struct mt7603_dev *dev);
213213

214214
void mt7603_pse_client_reset(struct mt7603_dev *dev);
215215

216+
int mt7603_set_channel(struct mt76_phy *mphy);
216217
int mt7603_mcu_set_channel(struct mt7603_dev *dev);
217218
int mt7603_mcu_set_eeprom(struct mt7603_dev *dev);
218219
void mt7603_mcu_exit(struct mt7603_dev *dev);

drivers/net/wireless/mediatek/mt76/mt7615/main.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,14 @@ static void mt7615_remove_interface(struct ieee80211_hw *hw,
282282
mt76_wcid_cleanup(&dev->mt76, &mvif->sta.wcid);
283283
}
284284

285-
int mt7615_set_channel(struct mt7615_phy *phy)
285+
int mt7615_set_channel(struct mt76_phy *mphy)
286286
{
287+
struct mt7615_phy *phy = mphy->priv;
287288
struct mt7615_dev *dev = phy->dev;
288289
bool ext_phy = phy != &dev->phy;
289290
int ret;
290291

291-
cancel_delayed_work_sync(&phy->mt76->mac_work);
292-
293-
mt7615_mutex_acquire(dev);
294-
295-
set_bit(MT76_RESET, &phy->mt76->state);
296-
297-
mt76_set_channel(phy->mt76);
292+
mt76_connac_pm_wake(mphy, &dev->pm);
298293

299294
if (is_mt7615(&dev->mt76) && dev->flash_eeprom) {
300295
ret = mt7615_mcu_apply_rx_dcoc(phy);
@@ -325,11 +320,8 @@ int mt7615_set_channel(struct mt7615_phy *phy)
325320
phy->chfreq = mt76_rr(dev, MT_CHFREQ(ext_phy));
326321

327322
out:
328-
clear_bit(MT76_RESET, &phy->mt76->state);
323+
mt76_connac_power_save_sched(mphy, &dev->pm);
329324

330-
mt7615_mutex_release(dev);
331-
332-
mt76_worker_schedule(&dev->mt76.tx_worker);
333325
if (!mt76_testmode_enabled(phy->mt76)) {
334326
unsigned long timeout = mt7615_get_macwork_timeout(dev);
335327

@@ -339,6 +331,7 @@ int mt7615_set_channel(struct mt7615_phy *phy)
339331

340332
return ret;
341333
}
334+
EXPORT_SYMBOL_GPL(mt7615_set_channel);
342335

343336
static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
344337
struct ieee80211_vif *vif, struct ieee80211_sta *sta,
@@ -425,11 +418,7 @@ static int mt7615_set_sar_specs(struct ieee80211_hw *hw,
425418
if (mt7615_firmware_offload(phy->dev))
426419
return mt76_connac_mcu_set_rate_txpower(phy->mt76);
427420

428-
ieee80211_stop_queues(hw);
429-
err = mt7615_set_channel(phy);
430-
ieee80211_wake_queues(hw);
431-
432-
return err;
421+
return mt76_update_channel(phy->mt76);
433422
}
434423

435424
static int mt7615_config(struct ieee80211_hw *hw, u32 changed)
@@ -448,9 +437,7 @@ static int mt7615_config(struct ieee80211_hw *hw, u32 changed)
448437
mt7615_mutex_release(dev);
449438
}
450439
#endif
451-
ieee80211_stop_queues(hw);
452-
ret = mt7615_set_channel(phy);
453-
ieee80211_wake_queues(hw);
440+
ret = mt76_update_channel(phy->mt76);
454441
}
455442

456443
mt7615_mutex_acquire(dev);

drivers/net/wireless/mediatek/mt76/mt7615/mcu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd)
21512151
if (cmd == MCU_EXT_CMD(SET_RX_PATH) ||
21522152
phy->mt76->hw->conf.flags & IEEE80211_CONF_MONITOR)
21532153
req.switch_reason = CH_SWITCH_NORMAL;
2154-
else if (phy->mt76->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
2154+
else if (phy->mt76->offchannel)
21552155
req.switch_reason = CH_SWITCH_SCAN_BYPASS_DPD;
21562156
else if (!cfg80211_reg_can_beacon(phy->mt76->hw->wiphy, chandef,
21572157
NL80211_IFTYPE_AP))

drivers/net/wireless/mediatek/mt76/mt7615/mmio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base,
182182
.sta_add = mt7615_mac_sta_add,
183183
.sta_remove = mt7615_mac_sta_remove,
184184
.update_survey = mt7615_update_channel,
185+
.set_channel = mt7615_set_channel,
185186
};
186187
struct mt76_bus_ops *bus_ops;
187188
struct ieee80211_ops *ops;

drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void mt7615_roc_work(struct work_struct *work);
457457
void mt7615_roc_timer(struct timer_list *timer);
458458
void mt7615_init_txpower(struct mt7615_dev *dev,
459459
struct ieee80211_supported_band *sband);
460-
int mt7615_set_channel(struct mt7615_phy *phy);
460+
int mt7615_set_channel(struct mt76_phy *mphy);
461461
void mt7615_init_work(struct mt7615_dev *dev);
462462

463463
int mt7615_mcu_restart(struct mt76_dev *dev);

0 commit comments

Comments
 (0)