Skip to content

Commit

Permalink
mt76: introduce phys array in mt76_dev structure
Browse files Browse the repository at this point in the history
Introduce phys array in mt76_dev structure to reference mt76_phy
supported by the chipset. This is a preliminary patch to introduce
newer chipset support.

Signed-off-by: Lorenzo Bianconi <[email protected]>
  • Loading branch information
LorenzoBianconi authored and nbd168 committed Jul 11, 2022
1 parent 8ccbb38 commit eb19ac8
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 97 deletions.
13 changes: 9 additions & 4 deletions dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,15 @@ void mt76_dma_cleanup(struct mt76_dev *dev)
mt76_worker_disable(&dev->tx_worker);
netif_napi_del(&dev->tx_napi);

for (i = 0; i < ARRAY_SIZE(dev->phy.q_tx); i++) {
mt76_dma_tx_cleanup(dev, dev->phy.q_tx[i], true);
if (dev->phy2)
mt76_dma_tx_cleanup(dev, dev->phy2->q_tx[i], true);
for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {
struct mt76_phy *phy = dev->phys[i];
int j;

if (!phy)
continue;

for (j = 0; j < ARRAY_SIZE(phy->q_tx); j++)
mt76_dma_tx_cleanup(dev, phy->q_tx[j], true);
}

for (i = 0; i < ARRAY_SIZE(dev->q_mcu); i++)
Expand Down
9 changes: 6 additions & 3 deletions mac80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)

struct mt76_phy *
mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
const struct ieee80211_ops *ops)
const struct ieee80211_ops *ops, u8 band_idx)
{
struct ieee80211_hw *hw;
unsigned int phy_size;
Expand All @@ -467,6 +467,7 @@ mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
phy->dev = dev;
phy->hw = hw;
phy->priv = hw->priv + phy_size;
phy->band_idx = band_idx;

hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
hw->wiphy->interface_modes =
Expand Down Expand Up @@ -519,7 +520,7 @@ int mt76_register_phy(struct mt76_phy *phy, bool vht,
if (ret)
return ret;

phy->dev->phy2 = phy;
phy->dev->phys[phy->band_idx] = phy;

return 0;
}
Expand All @@ -531,7 +532,7 @@ void mt76_unregister_phy(struct mt76_phy *phy)

mt76_tx_status_check(dev, true);
ieee80211_unregister_hw(phy->hw);
dev->phy2 = NULL;
dev->phys[phy->band_idx] = NULL;
}
EXPORT_SYMBOL_GPL(mt76_unregister_phy);

Expand All @@ -558,6 +559,8 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
phy = &dev->phy;
phy->dev = dev;
phy->hw = hw;
phy->band_idx = MT_BAND0;
dev->phys[phy->band_idx] = phy;

spin_lock_init(&dev->rx_lock);
spin_lock_init(&dev->lock);
Expand Down
43 changes: 28 additions & 15 deletions mt76.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ enum mt76_rxq_id {
__MT_RXQ_MAX
};

enum mt76_band_id {
MT_BAND0,
MT_BAND1,
MT_BAND2,
__MT_MAX_BAND
};

enum mt76_cipher_type {
MT_CIPHER_NONE,
MT_CIPHER_WEP40,
Expand Down Expand Up @@ -661,6 +668,7 @@ struct mt76_phy {
void *priv;

unsigned long state;
u8 band_idx;

struct mt76_queue *q_tx[__MT_TXQ_MAX];

Expand Down Expand Up @@ -700,8 +708,7 @@ struct mt76_phy {

struct mt76_dev {
struct mt76_phy phy; /* must be first */

struct mt76_phy *phy2;
struct mt76_phy *phys[__MT_MAX_BAND];

struct ieee80211_hw *hw;

Expand Down Expand Up @@ -891,7 +898,7 @@ mt76_wcid_hw(struct mt76_dev *dev, u16 wcid)
{
if (wcid <= MT76_N_WCIDS &&
mt76_wcid_mask_test(dev->wcid_phy_mask, wcid))
return dev->phy2->hw;
return dev->phys[MT_BAND1]->hw;

return dev->phy.hw;
}
Expand Down Expand Up @@ -946,7 +953,8 @@ void mt76_free_device(struct mt76_dev *dev);
void mt76_unregister_phy(struct mt76_phy *phy);

struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
const struct ieee80211_ops *ops);
const struct ieee80211_ops *ops,
u8 band_idx);
int mt76_register_phy(struct mt76_phy *phy, bool vht,
struct ieee80211_rate *rates, int n_rates);

Expand Down Expand Up @@ -1000,8 +1008,9 @@ static inline int mt76_init_mcu_queue(struct mt76_dev *dev, int qid, int idx,
static inline struct mt76_phy *
mt76_dev_phy(struct mt76_dev *dev, u8 phy_idx)
{
if (phy_idx && dev->phy2)
return dev->phy2;
if ((phy_idx == MT_BAND1 && dev->phys[phy_idx]) ||
(phy_idx == MT_BAND2 && dev->phys[phy_idx]))
return dev->phys[phy_idx];

return &dev->phy;
}
Expand Down Expand Up @@ -1120,13 +1129,17 @@ static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,
struct ieee80211_hw **hw)
{
#ifdef CONFIG_NL80211_TESTMODE
if (skb == dev->phy.test.tx_skb)
*hw = dev->phy.hw;
else if (dev->phy2 && skb == dev->phy2->test.tx_skb)
*hw = dev->phy2->hw;
else
return false;
return true;
int i;

for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {
struct mt76_phy *phy = dev->phys[i];

if (phy && skb == phy->test.tx_skb) {
*hw = dev->phys[i]->hw;
return true;
}
}
return false;
#else
return false;
#endif
Expand Down Expand Up @@ -1244,8 +1257,8 @@ mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb)
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hw *hw = dev->phy.hw;

if ((info->hw_queue & MT_TX_HW_QUEUE_EXT_PHY) && dev->phy2)
hw = dev->phy2->hw;
if ((info->hw_queue & MT_TX_HW_QUEUE_EXT_PHY) && dev->phys[MT_BAND1])
hw = dev->phys[MT_BAND1]->hw;

info->hw_queue &= ~MT_TX_HW_QUEUE_EXT_PHY;

Expand Down
4 changes: 2 additions & 2 deletions mt7615/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev)
return 0;

mt7615_cap_dbdc_enable(dev);
mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7615_ops);
mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7615_ops, MT_BAND1);
if (!mphy)
return -ENOMEM;

Expand Down Expand Up @@ -509,7 +509,7 @@ EXPORT_SYMBOL_GPL(mt7615_register_ext_phy);
void mt7615_unregister_ext_phy(struct mt7615_dev *dev)
{
struct mt7615_phy *phy = mt7615_ext_phy(dev);
struct mt76_phy *mphy = dev->mt76.phy2;
struct mt76_phy *mphy = dev->mt76.phys[MT_BAND1];

if (!phy)
return;
Expand Down
36 changes: 20 additions & 16 deletions mt7615/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static struct mt76_wcid *mt7615_rx_get_wcid(struct mt7615_dev *dev,

void mt7615_mac_reset_counters(struct mt7615_dev *dev)
{
struct mt76_phy *mphy_ext = dev->mt76.phys[MT_BAND1];
int i;

for (i = 0; i < 4; i++) {
Expand All @@ -118,8 +119,8 @@ void mt7615_mac_reset_counters(struct mt7615_dev *dev)

memset(dev->mt76.aggr_stats, 0, sizeof(dev->mt76.aggr_stats));
dev->mt76.phy.survey_time = ktime_get_boottime();
if (dev->mt76.phy2)
dev->mt76.phy2->survey_time = ktime_get_boottime();
if (mphy_ext)
mphy_ext->survey_time = ktime_get_boottime();

/* reset airtime counters */
mt76_rr(dev, MT_MIB_SDR9(0));
Expand Down Expand Up @@ -336,9 +337,9 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
struct mt76_phy *mphy = &dev->mt76.phy;
struct mt7615_phy *phy = &dev->phy;
struct mt7615_phy *phy2 = dev->mt76.phy2 ? dev->mt76.phy2->priv : NULL;
struct ieee80211_supported_band *sband;
struct ieee80211_hdr *hdr;
struct mt7615_phy *phy2;
__le32 *rxd = (__le32 *)skb->data;
u32 rxd0 = le32_to_cpu(rxd[0]);
u32 rxd1 = le32_to_cpu(rxd[1]);
Expand All @@ -355,6 +356,8 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
memset(status, 0, sizeof(*status));

chfreq = FIELD_GET(MT_RXD1_NORMAL_CH_FREQ, rxd1);

phy2 = dev->mt76.phys[MT_BAND1] ? dev->mt76.phys[MT_BAND1]->priv : NULL;
if (!phy2)
phy_idx = 0;
else if (phy2->chfreq == phy->chfreq)
Expand Down Expand Up @@ -498,7 +501,7 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
}

if (phy_idx == 1 && phy2) {
mphy = dev->mt76.phy2;
mphy = dev->mt76.phys[MT_BAND1];
phy = phy2;
status->phy_idx = phy_idx;
}
Expand Down Expand Up @@ -747,8 +750,8 @@ int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
tx_count = msta->rate_count;
}

if (ext_phy && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (ext_phy && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];

fc_type = (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE) >> 2;
fc_stype = (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE) >> 4;
Expand Down Expand Up @@ -1386,8 +1389,8 @@ static bool mt7615_fill_txs(struct mt7615_dev *dev, struct mt7615_sta *sta,
if (sta->rate_probe) {
struct mt7615_phy *phy = &dev->phy;

if (sta->wcid.ext_phy && dev->mt76.phy2)
phy = dev->mt76.phy2->priv;
if (sta->wcid.ext_phy && dev->mt76.phys[MT_BAND1])
phy = dev->mt76.phys[MT_BAND1]->priv;

mt7615_mac_set_rates(phy, sta, NULL, sta->rates);
}
Expand Down Expand Up @@ -1429,8 +1432,8 @@ static bool mt7615_fill_txs(struct mt7615_dev *dev, struct mt7615_sta *sta,
fallthrough;
case MT_PHY_TYPE_OFDM:
mphy = &dev->mphy;
if (sta->wcid.ext_phy && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (sta->wcid.ext_phy && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];

if (mphy->chandef.chan->band == NL80211_BAND_5GHZ)
sband = &mphy->sband_5g.sband;
Expand Down Expand Up @@ -1537,8 +1540,8 @@ static void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data)
if (wcidx >= MT7615_WTBL_STA || !sta)
goto out;

if (wcid->ext_phy && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (wcid->ext_phy && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];

if (mt7615_fill_txs(dev, msta, &info, txs_data))
ieee80211_tx_status_noskb(mphy->hw, sta, &info);
Expand Down Expand Up @@ -1955,21 +1958,22 @@ mt7615_phy_update_channel(struct mt76_phy *mphy, int idx)
static void mt7615_update_survey(struct mt7615_dev *dev)
{
struct mt76_dev *mdev = &dev->mt76;
struct mt76_phy *mphy_ext = mdev->phys[MT_BAND1];
ktime_t cur_time;

/* MT7615 can only update both phys simultaneously
* since some reisters are shared across bands.
*/

mt7615_phy_update_channel(&mdev->phy, 0);
if (mdev->phy2)
mt7615_phy_update_channel(mdev->phy2, 1);
if (mphy_ext)
mt7615_phy_update_channel(mphy_ext, 1);

cur_time = ktime_get_boottime();

mt76_update_survey_active_time(&mdev->phy, cur_time);
if (mdev->phy2)
mt76_update_survey_active_time(mdev->phy2, cur_time);
if (mphy_ext)
mt76_update_survey_active_time(mphy_ext, cur_time);

/* reset obss airtime */
mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_CLR);
Expand Down
26 changes: 13 additions & 13 deletions mt7615/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ mt7615_mcu_rx_csa_notify(struct mt7615_dev *dev, struct sk_buff *skb)
return;

if (ext_phy && ext_phy->omac_mask & BIT_ULL(c->omac_idx))
mphy = dev->mt76.phy2;
mphy = dev->mt76.phys[MT_BAND1];

ieee80211_iterate_active_interfaces_atomic(mphy->hw,
IEEE80211_IFACE_ITER_RESUME_ALL,
Expand All @@ -388,8 +388,8 @@ mt7615_mcu_rx_radar_detected(struct mt7615_dev *dev, struct sk_buff *skb)
!r->constant_prf_detected && !r->staggered_prf_detected)
return;

if (r->band_idx && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (r->band_idx && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];

if (mt76_phy_dfs_state(mphy) < MT_DFS_STATE_CAC)
return;
Expand Down Expand Up @@ -448,8 +448,8 @@ mt7615_mcu_scan_event(struct mt7615_dev *dev, struct sk_buff *skb)
struct mt7615_phy *phy;
struct mt76_phy *mphy;

if (*seq_num & BIT(7) && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (*seq_num & BIT(7) && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];
else
mphy = &dev->mt76.phy;

Expand All @@ -474,8 +474,8 @@ mt7615_mcu_roc_event(struct mt7615_dev *dev, struct sk_buff *skb)
skb_pull(skb, sizeof(struct mt7615_mcu_rxd));
event = (struct mt7615_roc_tlv *)skb->data;

if (event->dbdc_band && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (event->dbdc_band && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];
else
mphy = &dev->mt76.phy;

Expand All @@ -499,8 +499,8 @@ mt7615_mcu_beacon_loss_event(struct mt7615_dev *dev, struct sk_buff *skb)

skb_pull(skb, sizeof(struct mt7615_mcu_rxd));
event = (struct mt76_connac_beacon_loss_event *)skb->data;
if (band_idx && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (band_idx && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];
else
mphy = &dev->mt76.phy;

Expand All @@ -520,8 +520,8 @@ mt7615_mcu_bss_event(struct mt7615_dev *dev, struct sk_buff *skb)
skb_pull(skb, sizeof(struct mt7615_mcu_rxd));
event = (struct mt76_connac_mcu_bss_event *)skb->data;

if (band_idx && dev->mt76.phy2)
mphy = dev->mt76.phy2;
if (band_idx && dev->mt76.phys[MT_BAND1])
mphy = dev->mt76.phys[MT_BAND1];
else
mphy = &dev->mt76.phy;

Expand Down Expand Up @@ -2330,7 +2330,7 @@ int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy)

.bw = mt7615_mcu_chan_bw(chandef),
.band = chandef->center_freq1 > 4000,
.dbdc_en = !!dev->mt76.phy2,
.dbdc_en = !!dev->mt76.phys[MT_BAND1],
};
u16 center_freq = chandef->center_freq1;
int freq_idx;
Expand Down Expand Up @@ -2451,7 +2451,7 @@ int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy)

.bw = mt7615_mcu_chan_bw(chandef),
.band = chandef->center_freq1 > 4000,
.dbdc_en = !!dev->mt76.phy2,
.dbdc_en = !!dev->mt76.phys[MT_BAND1],
};
u16 center_freq = chandef->center_freq1;
int freq_idx;
Expand Down
2 changes: 1 addition & 1 deletion mt7615/mt7615.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ mt7615_hw_dev(struct ieee80211_hw *hw)
static inline struct mt7615_phy *
mt7615_ext_phy(struct mt7615_dev *dev)
{
struct mt76_phy *phy = dev->mt76.phy2;
struct mt76_phy *phy = dev->mt76.phys[MT_BAND1];

if (!phy)
return NULL;
Expand Down
Loading

0 comments on commit eb19ac8

Please sign in to comment.