Path: blob/main/sys/contrib/dev/mediatek/mt76/mt76x2/pci_main.c
48526 views
// SPDX-License-Identifier: ISC1/*2* Copyright (C) 2016 Felix Fietkau <[email protected]>3*/45#include "mt76x2.h"6#include "../mt76x02_mac.h"78static int9mt76x2_start(struct ieee80211_hw *hw)10{11struct mt76x02_dev *dev = hw->priv;1213mt76x02_mac_start(dev);14mt76x2_phy_start(dev);1516ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,17MT_MAC_WORK_INTERVAL);18ieee80211_queue_delayed_work(mt76_hw(dev), &dev->wdt_work,19MT_WATCHDOG_TIME);2021set_bit(MT76_STATE_RUNNING, &dev->mphy.state);22return 0;23}2425static void26mt76x2_stop(struct ieee80211_hw *hw, bool suspend)27{28struct mt76x02_dev *dev = hw->priv;2930clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);31mt76x2_stop_hardware(dev);32}3334int mt76x2e_set_channel(struct mt76_phy *phy)35{36struct mt76x02_dev *dev = container_of(phy->dev, struct mt76x02_dev, mt76);3738tasklet_disable(&dev->mt76.pre_tbtt_tasklet);39tasklet_disable(&dev->dfs_pd.dfs_tasklet);4041mt76x2_mac_stop(dev, true);42mt76x2_phy_set_channel(dev, &phy->chandef);4344mt76x02_mac_cc_reset(dev);45mt76x02_dfs_init_params(dev);4647mt76x2_mac_resume(dev);4849tasklet_enable(&dev->dfs_pd.dfs_tasklet);50tasklet_enable(&dev->mt76.pre_tbtt_tasklet);5152return 0;53}5455static int56mt76x2_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)57{58struct mt76x02_dev *dev = hw->priv;5960mutex_lock(&dev->mt76.mutex);6162if (changed & IEEE80211_CONF_CHANGE_MONITOR) {63if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))64dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;65else66dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;6768mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);69}7071if (changed & IEEE80211_CONF_CHANGE_POWER) {72struct mt76_phy *mphy = &dev->mphy;7374dev->txpower_conf = hw->conf.power_level * 2;75dev->txpower_conf = mt76_get_sar_power(mphy,76mphy->chandef.chan,77dev->txpower_conf);78/* convert to per-chain power for 2x2 devices */79dev->txpower_conf -= 6;8081if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) {82mt76x2_phy_set_txpower(dev);83mt76x02_tx_set_txpwr_auto(dev, dev->txpower_conf);84}85}8687mutex_unlock(&dev->mt76.mutex);8889if (changed & IEEE80211_CONF_CHANGE_CHANNEL)90mt76_update_channel(&dev->mphy);9192return 0;93}9495static void96mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,97u32 queues, bool drop)98{99}100101static int mt76x2_set_antenna(struct ieee80211_hw *hw, int radio_idx,102u32 tx_ant, u32 rx_ant)103{104struct mt76x02_dev *dev = hw->priv;105106if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)107return -EINVAL;108109mutex_lock(&dev->mt76.mutex);110111dev->mphy.chainmask = (tx_ant == 3) ? 0x202 : 0x101;112dev->mphy.antenna_mask = tx_ant;113114mt76_set_stream_caps(&dev->mphy, true);115mt76x2_phy_set_antenna(dev);116117mutex_unlock(&dev->mt76.mutex);118119return 0;120}121122const struct ieee80211_ops mt76x2_ops = {123.add_chanctx = ieee80211_emulate_add_chanctx,124.remove_chanctx = ieee80211_emulate_remove_chanctx,125.change_chanctx = ieee80211_emulate_change_chanctx,126.switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,127.tx = mt76x02_tx,128.start = mt76x2_start,129.stop = mt76x2_stop,130.add_interface = mt76x02_add_interface,131.remove_interface = mt76x02_remove_interface,132.config = mt76x2_config,133.configure_filter = mt76x02_configure_filter,134.bss_info_changed = mt76x02_bss_info_changed,135.sta_state = mt76_sta_state,136.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,137.set_key = mt76x02_set_key,138.conf_tx = mt76x02_conf_tx,139.sw_scan_start = mt76_sw_scan,140.sw_scan_complete = mt76x02_sw_scan_complete,141.flush = mt76x2_flush,142.ampdu_action = mt76x02_ampdu_action,143.get_txpower = mt76_get_txpower,144.wake_tx_queue = mt76_wake_tx_queue,145.sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,146.release_buffered_frames = mt76_release_buffered_frames,147.set_coverage_class = mt76x02_set_coverage_class,148.get_survey = mt76_get_survey,149.set_tim = mt76_set_tim,150.set_antenna = mt76x2_set_antenna,151.get_antenna = mt76_get_antenna,152.set_rts_threshold = mt76x02_set_rts_threshold,153.reconfig_complete = mt76x02_reconfig_complete,154.set_sar_specs = mt76x2_set_sar_specs,155};156157158159