Skip to content

Commit

Permalink
mt76: mt7915: introduce band_idx in mt7915_phy
Browse files Browse the repository at this point in the history
The wfsys of MT7986 has only single adie chip for non-dbdc devices,
and it binds to band1 by default. Hence this patch adds band_idx to
explicitly configure phy accordingly.

Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
Co-developed-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
Reviewed-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
Bo Jiao authored and nbd168 committed Feb 14, 2022
1 parent 6ef22f4 commit 7f1818c
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 158 deletions.
6 changes: 2 additions & 4 deletions mt76_connac_mcu.c
Expand Up @@ -1501,7 +1501,6 @@ int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,
int ext_channels_num = max_t(int, sreq->n_channels - 32, 0);
struct ieee80211_channel **scan_list = sreq->channels;
struct mt76_dev *mdev = phy->dev;
bool ext_phy = phy == mdev->phy2;
struct mt76_connac_mcu_scan_channel *chan;
struct mt76_connac_hw_scan_req *req;
struct sk_buff *skb;
Expand All @@ -1515,7 +1514,7 @@ int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,

req = (struct mt76_connac_hw_scan_req *)skb_put(skb, sizeof(*req));

req->seq_num = mvif->scan_seq_num | ext_phy << 7;
req->seq_num = mvif->scan_seq_num | mvif->band_idx << 7;
req->bss_idx = mvif->idx;
req->scan_type = sreq->n_ssids ? 1 : 0;
req->probe_req_num = sreq->n_ssids ? 2 : 0;
Expand Down Expand Up @@ -1623,7 +1622,6 @@ int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,
struct mt76_connac_mcu_scan_channel *chan;
struct mt76_connac_sched_scan_req *req;
struct mt76_dev *mdev = phy->dev;
bool ext_phy = phy == mdev->phy2;
struct cfg80211_match_set *match;
struct cfg80211_ssid *ssid;
struct sk_buff *skb;
Expand All @@ -1637,7 +1635,7 @@ int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,

req = (struct mt76_connac_sched_scan_req *)skb_put(skb, sizeof(*req));
req->version = 1;
req->seq_num = mvif->scan_seq_num | ext_phy << 7;
req->seq_num = mvif->scan_seq_num | mvif->band_idx << 7;

if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
u8 *addr = is_mt7663(phy->dev) ? req->mt7663.random_mac
Expand Down
8 changes: 4 additions & 4 deletions mt7915/debugfs.c
Expand Up @@ -548,20 +548,20 @@ mt7915_ampdu_stat_read_phy(struct mt7915_phy *phy,

/* Tx ampdu stat */
for (i = 0; i < ARRAY_SIZE(range); i++)
range[i] = mt76_rr(dev, MT_MIB_ARNG(ext_phy, i));
range[i] = mt76_rr(dev, MT_MIB_ARNG(phy->band_idx, i));

for (i = 0; i < ARRAY_SIZE(bound); i++)
bound[i] = MT_MIB_ARNCR_RANGE(range[i / 4], i % 4) + 1;

seq_printf(file, "\nPhy %d\n", ext_phy);
seq_printf(file, "\nPhy %d, Phy band %d\n", ext_phy, phy->band_idx);

seq_printf(file, "Length: %8d | ", bound[0]);
for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
seq_printf(file, "%3d -%3d | ",
bound[i] + 1, bound[i + 1]);

seq_puts(file, "\nCount: ");
n = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
n = phy->band_idx ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
for (i = 0; i < ARRAY_SIZE(bound); i++)
seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i + n]);
seq_puts(file, "\n");
Expand Down Expand Up @@ -898,7 +898,7 @@ int mt7915_init_debugfs(struct mt7915_phy *phy)
debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
mt7915_twt_stats);
debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger);
if (!dev->dbdc_support || ext_phy) {
if (!dev->dbdc_support || phy->band_idx) {
debugfs_create_u32("dfs_hw_pattern", 0400, dir,
&dev->hw_pattern);
debugfs_create_file("radar_trigger", 0200, dir, dev,
Expand Down
28 changes: 16 additions & 12 deletions mt7915/dma.c
Expand Up @@ -310,10 +310,12 @@ static int mt7915_dma_enable(struct mt7915_dev *dev)
/* enable interrupts for TX/RX rings */
irq_mask = MT_INT_RX_DONE_MCU |
MT_INT_TX_DONE_MCU |
MT_INT_MCU_CMD |
MT_INT_BAND0_RX_DONE;
MT_INT_MCU_CMD;

if (dev->dbdc_support)
if (!dev->phy.band_idx)
irq_mask |= MT_INT_BAND0_RX_DONE;

if (dev->dbdc_support || dev->phy.band_idx)
irq_mask |= MT_INT_BAND1_RX_DONE;

mt7915_irq_enable(dev, irq_mask);
Expand All @@ -338,7 +340,7 @@ int mt7915_dma_init(struct mt7915_dev *dev)

/* init tx queue */
ret = mt7915_init_tx_queues(&dev->phy,
MT_TXQ_ID(0),
MT_TXQ_ID(dev->phy.band_idx),
MT7915_TX_RING_SIZE,
MT_TXQ_RING_BASE(0));
if (ret)
Expand Down Expand Up @@ -387,13 +389,15 @@ int mt7915_dma_init(struct mt7915_dev *dev)
return ret;

/* rx data queue for band0 */
ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MAIN],
MT_RXQ_ID(MT_RXQ_MAIN),
MT7915_RX_RING_SIZE,
MT_RX_BUF_SIZE,
MT_RXQ_RING_BASE(MT_RXQ_MAIN));
if (ret)
return ret;
if (!dev->phy.band_idx) {
ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MAIN],
MT_RXQ_ID(MT_RXQ_MAIN),
MT7915_RX_RING_SIZE,
MT_RX_BUF_SIZE,
MT_RXQ_RING_BASE(MT_RXQ_MAIN));
if (ret)
return ret;
}

/* tx free notify event from WA for band0 */
if (!is_mt7915(mdev)) {
Expand All @@ -406,7 +410,7 @@ int mt7915_dma_init(struct mt7915_dev *dev)
return ret;
}

if (dev->dbdc_support) {
if (dev->dbdc_support || dev->phy.band_idx) {
/* rx data queue for band1 */
ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_EXT],
MT_RXQ_ID(MT_RXQ_EXT),
Expand Down
18 changes: 9 additions & 9 deletions mt7915/eeprom.c
Expand Up @@ -130,14 +130,14 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
static void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy)
{
struct mt7915_dev *dev = phy->dev;
bool ext_phy = phy != &dev->phy;
u8 *eeprom = dev->mt76.eeprom.data;
u32 val;

val = eeprom[MT_EE_WIFI_CONF + ext_phy];
val = eeprom[MT_EE_WIFI_CONF + phy->band_idx];
val = FIELD_GET(MT_EE_WIFI_CONF0_BAND_SEL, val);
if (val == MT_EE_BAND_SEL_DEFAULT && dev->dbdc_support)
val = ext_phy ? MT_EE_BAND_SEL_5GHZ : MT_EE_BAND_SEL_2GHZ;
if (val == MT_EE_BAND_SEL_DEFAULT &&
(!is_mt7915(&dev->mt76) || dev->dbdc_support))
val = phy->band_idx ? MT_EE_BAND_SEL_5GHZ : MT_EE_BAND_SEL_2GHZ;

switch (val) {
case MT_EE_BAND_SEL_5GHZ:
Expand Down Expand Up @@ -168,7 +168,7 @@ void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev,
eeprom[MT_EE_WIFI_CONF]);
} else {
nss = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
eeprom[MT_EE_WIFI_CONF + ext_phy]);
eeprom[MT_EE_WIFI_CONF + phy->band_idx]);
}

if (!nss || nss > 4)
Expand All @@ -181,12 +181,12 @@ void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev,
if (is_mt7915(&dev->mt76)) {
nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B0,
eeprom[MT_EE_WIFI_CONF + 3]);
if (ext_phy)
if (phy->band_idx)
nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B1,
eeprom[MT_EE_WIFI_CONF + 3]);
} else {
nss_band = FIELD_GET(MT_EE_WIFI_CONF_STREAM_NUM,
eeprom[MT_EE_WIFI_CONF + 2 + ext_phy]);
eeprom[MT_EE_WIFI_CONF + 2 + phy->band_idx]);
}

nss_band_max = is_mt7986(&dev->mt76) ?
Expand All @@ -201,8 +201,8 @@ void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev,

if (nss_band > nss) {
dev_warn(dev->mt76.dev,
"nss mismatch, nss(%d) nss_band(%d) ext_phy(%d)\n",
nss, nss_band, ext_phy);
"nss mismatch, nss(%d) nss_band(%d) band(%d) ext_phy(%d)\n",
nss, nss_band, phy->band_idx, ext_phy);
nss = nss_band;
}

Expand Down
34 changes: 31 additions & 3 deletions mt7915/init.c
Expand Up @@ -489,6 +489,9 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
phy->dev = dev;
phy->mt76 = mphy;

/* Bind main phy to band0 and ext_phy to band1 for dbdc case */
phy->band_idx = 1;

INIT_DELAYED_WORK(&mphy->mac_work, mt7915_mac_work);

mt7915_eeprom_parse_hw_cap(dev, phy);
Expand All @@ -508,7 +511,7 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)

/* init wiphy according to mphy and phy */
mt7915_init_wiphy(mphy->hw);
ret = mt7915_init_tx_queues(phy, MT_TXQ_ID(1),
ret = mt7915_init_tx_queues(phy, MT_TXQ_ID(phy->band_idx),
MT7915_TX_RING_SIZE,
MT_TXQ_RING_BASE(1));
if (ret)
Expand Down Expand Up @@ -600,6 +603,32 @@ static void mt7915_wfsys_reset(struct mt7915_dev *dev)
}
}

static bool mt7915_band_config(struct mt7915_dev *dev)
{
bool ret = true;

dev->phy.band_idx = 0;

if (is_mt7986(&dev->mt76)) {
u32 sku = mt7915_check_adie(dev, true);

/*
* for mt7986, dbdc support is determined by the number
* of adie chips and the main phy is bound to band1 when
* dbdc is disabled.
*/
if (sku == MT7975_ONE_ADIE || sku == MT7976_ONE_ADIE) {
dev->phy.band_idx = 1;
ret = false;
}
} else {
ret = is_mt7915(&dev->mt76) ?
!!(mt76_rr(dev, MT_HW_BOUND) & BIT(5)) : true;
}

return ret;
}

static int mt7915_init_hardware(struct mt7915_dev *dev)
{
int ret, idx;
Expand All @@ -608,8 +637,7 @@ static int mt7915_init_hardware(struct mt7915_dev *dev)

INIT_WORK(&dev->init_work, mt7915_init_work);

dev->dbdc_support = is_mt7915(&dev->mt76) ?
!!(mt76_rr(dev, MT_HW_BOUND) & BIT(5)) : true;
dev->dbdc_support = mt7915_band_config(dev);

/* If MCU was already running, it is likely in a bad state */
if (mt76_get_field(dev, MT_TOP_MISC, MT_TOP_MISC_FW_STATE) >
Expand Down

0 comments on commit 7f1818c

Please sign in to comment.