Skip to content

Commit

Permalink
mt76: move channel state to struct mt76_phy
Browse files Browse the repository at this point in the history
Add support for an extra wiphy in mt76_set_channel and mt76_get_survey
This is preparation for supporting multiple wiphys per device to support the
concurrent dual-band feature of MT7615D

Signed-off-by: Felix Fietkau <[email protected]>
  • Loading branch information
nbd168 committed Nov 20, 2019
1 parent e5e755a commit ee36c8e
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 137 deletions.
71 changes: 42 additions & 29 deletions mac80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ static void mt76_init_stream_cap(struct mt76_dev *dev,
void mt76_set_stream_caps(struct mt76_dev *dev, bool vht)
{
if (dev->cap.has_2ghz)
mt76_init_stream_cap(dev, &dev->sband_2g.sband, false);
mt76_init_stream_cap(dev, &dev->phy.sband_2g.sband, false);
if (dev->cap.has_5ghz)
mt76_init_stream_cap(dev, &dev->sband_5g.sband, vht);
mt76_init_stream_cap(dev, &dev->phy.sband_5g.sband, vht);
}
EXPORT_SYMBOL_GPL(mt76_set_stream_caps);

Expand Down Expand Up @@ -187,8 +187,8 @@ mt76_init_sband(struct mt76_dev *dev, struct mt76_sband *msband,
sband->n_channels = n_chan;
sband->bitrates = rates;
sband->n_bitrates = n_rates;
dev->chandef.chan = &sband->channels[0];
dev->chan_state = &msband->chan[0];
dev->phy.chandef.chan = &sband->channels[0];
dev->phy.chan_state = &msband->chan[0];

ht_cap = &sband->ht_cap;
ht_cap->ht_supported = true;
Expand Down Expand Up @@ -223,9 +223,9 @@ static int
mt76_init_sband_2g(struct mt76_dev *dev, struct ieee80211_rate *rates,
int n_rates)
{
dev->hw->wiphy->bands[NL80211_BAND_2GHZ] = &dev->sband_2g.sband;
dev->hw->wiphy->bands[NL80211_BAND_2GHZ] = &dev->phy.sband_2g.sband;

return mt76_init_sband(dev, &dev->sband_2g,
return mt76_init_sband(dev, &dev->phy.sband_2g,
mt76_channels_2ghz,
ARRAY_SIZE(mt76_channels_2ghz),
rates, n_rates, false);
Expand All @@ -235,9 +235,9 @@ static int
mt76_init_sband_5g(struct mt76_dev *dev, struct ieee80211_rate *rates,
int n_rates, bool vht)
{
dev->hw->wiphy->bands[NL80211_BAND_5GHZ] = &dev->sband_5g.sband;
dev->hw->wiphy->bands[NL80211_BAND_5GHZ] = &dev->phy.sband_5g.sband;

return mt76_init_sband(dev, &dev->sband_5g,
return mt76_init_sband(dev, &dev->phy.sband_5g,
mt76_channels_5ghz,
ARRAY_SIZE(mt76_channels_5ghz),
rates, n_rates, vht);
Expand Down Expand Up @@ -427,23 +427,32 @@ bool mt76_has_tx_pending(struct mt76_dev *dev)
EXPORT_SYMBOL_GPL(mt76_has_tx_pending);

static struct mt76_channel_state *
mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c)
mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c)
{
struct mt76_sband *msband;
int idx;

if (c->band == NL80211_BAND_2GHZ)
msband = &dev->sband_2g;
msband = &phy->sband_2g;
else
msband = &dev->sband_5g;
msband = &phy->sband_5g;

idx = c - &msband->sband.channels[0];
return &msband->chan[idx];
}

static void
mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time)
{
struct mt76_channel_state *state = phy->chan_state;

state->cc_active += ktime_to_us(ktime_sub(time,
phy->survey_time));
phy->survey_time = time;
}

void mt76_update_survey(struct mt76_dev *dev)
{
struct mt76_channel_state *state = dev->chan_state;
ktime_t cur_time;

if (!test_bit(MT76_STATE_RUNNING, &dev->state))
Expand All @@ -453,11 +462,13 @@ void mt76_update_survey(struct mt76_dev *dev)
dev->drv->update_survey(dev);

cur_time = ktime_get_boottime();
state->cc_active += ktime_to_us(ktime_sub(cur_time,
dev->survey_time));
dev->survey_time = cur_time;
mt76_update_survey_active_time(&dev->phy, cur_time);
if (dev->phy2)
mt76_update_survey_active_time(dev->phy2, cur_time);

if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME) {
struct mt76_channel_state *state = dev->phy.chan_state;

spin_lock_bh(&dev->cc_lock);
state->cc_bss_rx += dev->cur_cc_bss_rx;
dev->cur_cc_bss_rx = 0;
Expand All @@ -466,31 +477,33 @@ void mt76_update_survey(struct mt76_dev *dev)
}
EXPORT_SYMBOL_GPL(mt76_update_survey);

void mt76_set_channel(struct mt76_dev *dev)
void mt76_set_channel(struct mt76_phy *phy)
{
struct ieee80211_hw *hw = dev->hw;
struct mt76_dev *dev = phy->dev;
struct ieee80211_hw *hw = phy->hw;
struct cfg80211_chan_def *chandef = &hw->conf.chandef;
bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL;
int timeout = HZ / 5;

wait_event_timeout(dev->tx_wait, !mt76_has_tx_pending(dev), timeout);
mt76_update_survey(dev);

dev->chandef = *chandef;
dev->chan_state = mt76_channel_state(dev, chandef->chan);
phy->chandef = *chandef;
phy->chan_state = mt76_channel_state(phy, chandef->chan);

if (!offchannel)
dev->main_chan = chandef->chan;
phy->main_chan = chandef->chan;

if (chandef->chan != dev->main_chan)
memset(dev->chan_state, 0, sizeof(*dev->chan_state));
if (chandef->chan != phy->main_chan)
memset(phy->chan_state, 0, sizeof(*phy->chan_state));
}
EXPORT_SYMBOL_GPL(mt76_set_channel);

int mt76_get_survey(struct ieee80211_hw *hw, int idx,
struct survey_info *survey)
{
struct mt76_dev *dev = hw->priv;
struct mt76_phy *phy = hw->priv;
struct mt76_dev *dev = phy->dev;
struct mt76_sband *sband;
struct ieee80211_channel *chan;
struct mt76_channel_state *state;
Expand All @@ -500,10 +513,10 @@ int mt76_get_survey(struct ieee80211_hw *hw, int idx,
if (idx == 0 && dev->drv->update_survey)
mt76_update_survey(dev);

sband = &dev->sband_2g;
sband = &phy->sband_2g;
if (idx >= sband->sband.n_channels) {
idx -= sband->sband.n_channels;
sband = &dev->sband_5g;
sband = &phy->sband_5g;
}

if (idx >= sband->sband.n_channels) {
Expand All @@ -512,13 +525,13 @@ int mt76_get_survey(struct ieee80211_hw *hw, int idx,
}

chan = &sband->sband.channels[idx];
state = mt76_channel_state(dev, chan);
state = mt76_channel_state(phy, chan);

memset(survey, 0, sizeof(*survey));
survey->channel = chan;
survey->filled = SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY;
survey->filled |= dev->drv->survey_flags;
if (chan == dev->main_chan) {
if (chan == phy->main_chan) {
survey->filled |= SURVEY_INFO_IN_USE;

if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME)
Expand Down Expand Up @@ -1026,11 +1039,11 @@ int mt76_get_rate(struct mt76_dev *dev,
int i, offset = 0, len = sband->n_bitrates;

if (cck) {
if (sband == &dev->sband_5g.sband)
if (sband == &dev->phy.sband_5g.sband)
return 0;

idx &= ~BIT(2); /* short preamble */
} else if (sband == &dev->sband_2g.sband) {
} else if (sband == &dev->phy.sband_2g.sband) {
offset = 4;
}

Expand Down
19 changes: 11 additions & 8 deletions mt76.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define MT_SKB_HEAD_LEN 128

struct mt76_dev;
struct mt76_phy;
struct mt76_wcid;

struct mt76_reg_pair {
Expand Down Expand Up @@ -456,6 +457,15 @@ struct mt76_rx_status {
struct mt76_phy {
struct ieee80211_hw *hw;
struct mt76_dev *dev;

struct cfg80211_chan_def chandef;
struct ieee80211_channel *main_chan;

struct mt76_channel_state *chan_state;
ktime_t survey_time;

struct mt76_sband sband_2g;
struct mt76_sband sband_5g;
};

struct mt76_dev {
Expand All @@ -464,10 +474,7 @@ struct mt76_dev {
struct mt76_phy *phy2;

struct ieee80211_hw *hw;
struct cfg80211_chan_def chandef;
struct ieee80211_channel *main_chan;

struct mt76_channel_state *chan_state;
spinlock_t lock;
spinlock_t cc_lock;

Expand Down Expand Up @@ -522,8 +529,6 @@ struct mt76_dev {
int beacon_int;
u8 beacon_mask;

struct mt76_sband sband_2g;
struct mt76_sband sband_5g;
struct debugfs_blob_wrapper eeprom;
struct debugfs_blob_wrapper otp;
struct mt76_hw_cap cap;
Expand All @@ -543,8 +548,6 @@ struct mt76_dev {

u8 csa_complete;

ktime_t survey_time;

u32 rxfilter;

union {
Expand Down Expand Up @@ -750,7 +753,7 @@ void mt76_release_buffered_frames(struct ieee80211_hw *hw,
enum ieee80211_frame_release_type reason,
bool more_data);
bool mt76_has_tx_pending(struct mt76_dev *dev);
void mt76_set_channel(struct mt76_dev *dev);
void mt76_set_channel(struct mt76_phy *phy);
void mt76_update_survey(struct mt76_dev *dev);
int mt76_get_survey(struct ieee80211_hw *hw, int idx,
struct survey_info *survey);
Expand Down
2 changes: 1 addition & 1 deletion mt7603/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ int mt7603_register_device(struct mt7603_dev *dev)
return ret;

mt7603_init_debugfs(dev);
mt7603_init_txpower(dev, &dev->mt76.sband_2g.sband);
mt7603_init_txpower(dev, &dev->mphy.sband_2g.sband);

return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions mt7603/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void mt7603_mac_set_timing(struct mt7603_dev *dev)
int sifs;
u32 val;

if (dev->mt76.chandef.chan->band == NL80211_BAND_5GHZ)
if (dev->mphy.chandef.chan->band == NL80211_BAND_5GHZ)
sifs = 16;
else
sifs = 10;
Expand Down Expand Up @@ -456,7 +456,7 @@ void mt7603_mac_sta_poll(struct mt7603_dev *dev)
return;

spin_lock_bh(&dev->mt76.cc_lock);
dev->mt76.chan_state->cc_tx += total_airtime;
dev->mphy.chan_state->cc_tx += total_airtime;
spin_unlock_bh(&dev->mt76.cc_lock);
}

Expand Down Expand Up @@ -502,7 +502,7 @@ mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb)
memset(status, 0, sizeof(*status));

i = FIELD_GET(MT_RXD1_NORMAL_CH_FREQ, rxd1);
sband = (i & 1) ? &dev->mt76.sband_5g.sband : &dev->mt76.sband_2g.sband;
sband = (i & 1) ? &dev->mphy.sband_5g.sband : &dev->mphy.sband_2g.sband;
i >>= 1;

idx = FIELD_GET(MT_RXD2_NORMAL_WLAN_IDX, rxd2);
Expand Down Expand Up @@ -668,7 +668,7 @@ mt7603_mac_tx_rate_val(struct mt7603_dev *dev,
*bw = 1;
} else {
const struct ieee80211_rate *r;
int band = dev->mt76.chandef.chan->band;
int band = dev->mphy.chandef.chan->band;
u16 val;

nss = 1;
Expand Down Expand Up @@ -1156,10 +1156,10 @@ mt7603_fill_txs(struct mt7603_dev *dev, struct mt7603_sta *sta,
cck = true;
/* fall through */
case MT_PHY_TYPE_OFDM:
if (dev->mt76.chandef.chan->band == NL80211_BAND_5GHZ)
sband = &dev->mt76.sband_5g.sband;
if (dev->mphy.chandef.chan->band == NL80211_BAND_5GHZ)
sband = &dev->mphy.sband_5g.sband;
else
sband = &dev->mt76.sband_2g.sband;
sband = &dev->mphy.sband_2g.sband;
final_rate &= GENMASK(5, 0);
final_rate = mt76_get_rate(&dev->mt76, sband, final_rate,
cck);
Expand Down Expand Up @@ -1574,7 +1574,7 @@ void mt7603_update_channel(struct mt76_dev *mdev)
struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
struct mt76_channel_state *state;

state = mdev->chan_state;
state = mdev->phy.chan_state;
state->cc_busy += mt76_rr(dev, MT_MIB_STAT_CCA);
}

Expand Down
8 changes: 4 additions & 4 deletions mt7603/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mt7603_start(struct ieee80211_hw *hw)

mt7603_mac_reset_counters(dev);
mt7603_mac_start(dev);
dev->mt76.survey_time = ktime_get_boottime();
dev->mphy.survey_time = ktime_get_boottime();
set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
mt7603_mac_work(&dev->mt76.mac_work.work);

Expand Down Expand Up @@ -146,13 +146,13 @@ mt7603_set_channel(struct mt7603_dev *dev, struct cfg80211_chan_def *def)
set_bit(MT76_RESET, &dev->mt76.state);

mt7603_beacon_set_timer(dev, -1, 0);
mt76_set_channel(&dev->mt76);
mt76_set_channel(&dev->mphy);
mt7603_mac_stop(dev);

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

dev->mt76.chandef = *def;
dev->mphy.chandef = *def;
mt76_rmw_field(dev, MT_AGG_BWCR, MT_AGG_BWCR_BW, bw);
ret = mt7603_mcu_set_channel(dev);
if (ret) {
Expand Down Expand Up @@ -190,7 +190,7 @@ mt7603_set_channel(struct mt7603_dev *dev, struct cfg80211_chan_def *def)
mt76_rr(dev, MT_MIB_STAT_PSCCA);
mt7603_cca_stats_reset(dev);

dev->mt76.survey_time = ktime_get_boottime();
dev->mphy.survey_time = ktime_get_boottime();

mt7603_init_edcca(dev);

Expand Down
6 changes: 3 additions & 3 deletions mt7603/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev)
u8 temp_comp_power[17];
u8 reserved;
} req = {
.center_channel = dev->mt76.chandef.chan->hw_value,
.center_channel = dev->mphy.chandef.chan->hw_value,
#define EEP_VAL(n) ((u8 *)dev->mt76.eeprom.data)[n]
.tssi = EEP_VAL(MT_EE_NIC_CONF_1 + 1),
.temp_comp = EEP_VAL(MT_EE_NIC_CONF_1),
Expand Down Expand Up @@ -430,7 +430,7 @@ static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev)

int mt7603_mcu_set_channel(struct mt7603_dev *dev)
{
struct cfg80211_chan_def *chandef = &dev->mt76.chandef;
struct cfg80211_chan_def *chandef = &dev->mphy.chandef;
struct ieee80211_hw *hw = mt76_hw(dev);
int n_chains = hweight8(dev->mt76.antenna_mask);
struct {
Expand All @@ -452,7 +452,7 @@ int mt7603_mcu_set_channel(struct mt7603_dev *dev)
s8 tx_power;
int i, ret;

if (dev->mt76.chandef.width == NL80211_CHAN_WIDTH_40) {
if (dev->mphy.chandef.width == NL80211_CHAN_WIDTH_40) {
req.bw = MT_BW_40;
if (chandef->center_freq1 > chandef->chan->center_freq)
req.center_chan += 2;
Expand Down
Loading

0 comments on commit ee36c8e

Please sign in to comment.