Skip to content

Commit 955e823

Browse files
committed
wifi: mt76: add multi-radio support to a few core hw ops
Iterate over all phys if multi-radio is supported by the driver Link: https://patch.msgid.link/[email protected] Signed-off-by: Felix Fietkau <[email protected]>
1 parent 38a45be commit 955e823

File tree

1 file changed

+68
-20
lines changed

1 file changed

+68
-20
lines changed

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

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,22 @@ void mt76_free_device(struct mt76_dev *dev)
815815
}
816816
EXPORT_SYMBOL_GPL(mt76_free_device);
817817

818+
static struct mt76_phy *
819+
mt76_vif_phy(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
820+
{
821+
struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;
822+
struct mt76_chanctx *ctx;
823+
824+
if (!hw->wiphy->n_radio)
825+
return hw->priv;
826+
827+
if (!mlink->ctx)
828+
return NULL;
829+
830+
ctx = (struct mt76_chanctx *)mlink->ctx->drv_priv;
831+
return ctx->phy;
832+
}
833+
818834
static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
819835
{
820836
struct sk_buff *skb = phy->rx_amsdu[q].head;
@@ -1023,33 +1039,53 @@ int mt76_update_channel(struct mt76_phy *phy)
10231039
}
10241040
EXPORT_SYMBOL_GPL(mt76_update_channel);
10251041

1042+
static struct mt76_sband *
1043+
mt76_get_survey_sband(struct mt76_phy *phy, int *idx)
1044+
{
1045+
if (*idx < phy->sband_2g.sband.n_channels)
1046+
return &phy->sband_2g;
1047+
1048+
*idx -= phy->sband_2g.sband.n_channels;
1049+
if (*idx < phy->sband_5g.sband.n_channels)
1050+
return &phy->sband_5g;
1051+
1052+
*idx -= phy->sband_5g.sband.n_channels;
1053+
if (*idx < phy->sband_6g.sband.n_channels)
1054+
return &phy->sband_6g;
1055+
1056+
*idx -= phy->sband_6g.sband.n_channels;
1057+
return NULL;
1058+
}
1059+
10261060
int mt76_get_survey(struct ieee80211_hw *hw, int idx,
10271061
struct survey_info *survey)
10281062
{
10291063
struct mt76_phy *phy = hw->priv;
10301064
struct mt76_dev *dev = phy->dev;
1031-
struct mt76_sband *sband;
1065+
struct mt76_sband *sband = NULL;
10321066
struct ieee80211_channel *chan;
10331067
struct mt76_channel_state *state;
1068+
int phy_idx = 0;
10341069
int ret = 0;
10351070

10361071
mutex_lock(&dev->mutex);
1037-
if (idx == 0 && dev->drv->update_survey)
1038-
mt76_update_survey(phy);
1039-
1040-
if (idx >= phy->sband_2g.sband.n_channels +
1041-
phy->sband_5g.sband.n_channels) {
1042-
idx -= (phy->sband_2g.sband.n_channels +
1043-
phy->sband_5g.sband.n_channels);
1044-
sband = &phy->sband_6g;
1045-
} else if (idx >= phy->sband_2g.sband.n_channels) {
1046-
idx -= phy->sband_2g.sband.n_channels;
1047-
sband = &phy->sband_5g;
1048-
} else {
1049-
sband = &phy->sband_2g;
1072+
1073+
for (phy_idx = 0; phy_idx < ARRAY_SIZE(dev->phys); phy_idx++) {
1074+
sband = NULL;
1075+
phy = dev->phys[phy_idx];
1076+
if (!phy || phy->hw != hw)
1077+
continue;
1078+
1079+
sband = mt76_get_survey_sband(phy, &idx);
1080+
1081+
if (idx == 0 && phy->dev->drv->update_survey)
1082+
mt76_update_survey(phy);
1083+
1084+
if (sband || !hw->wiphy->n_radio)
1085+
break;
10501086
}
10511087

1052-
if (idx >= sband->sband.n_channels) {
1088+
if (!sband) {
10531089
ret = -ENOENT;
10541090
goto out;
10551091
}
@@ -1555,6 +1591,10 @@ int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
15551591
struct mt76_dev *dev = phy->dev;
15561592
enum mt76_sta_event ev;
15571593

1594+
phy = mt76_vif_phy(hw, vif);
1595+
if (!phy)
1596+
return -EINVAL;
1597+
15581598
if (old_state == IEEE80211_STA_NOTEXIST &&
15591599
new_state == IEEE80211_STA_NONE)
15601600
return mt76_sta_add(phy, vif, sta);
@@ -1659,10 +1699,14 @@ EXPORT_SYMBOL_GPL(mt76_wcid_add_poll);
16591699
int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
16601700
unsigned int link_id, int *dbm)
16611701
{
1662-
struct mt76_phy *phy = hw->priv;
1663-
int n_chains = hweight16(phy->chainmask);
1664-
int delta = mt76_tx_power_nss_delta(n_chains);
1702+
struct mt76_phy *phy = mt76_vif_phy(hw, vif);
1703+
int n_chains, delta;
16651704

1705+
if (!phy)
1706+
return -EINVAL;
1707+
1708+
n_chains = hweight16(phy->chainmask);
1709+
delta = mt76_tx_power_nss_delta(n_chains);
16661710
*dbm = DIV_ROUND_UP(phy->txpower_cur + delta, 2);
16671711

16681712
return 0;
@@ -1837,10 +1881,14 @@ int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
18371881
{
18381882
struct mt76_phy *phy = hw->priv;
18391883
struct mt76_dev *dev = phy->dev;
1884+
int i;
18401885

18411886
mutex_lock(&dev->mutex);
1842-
*tx_ant = phy->antenna_mask;
1843-
*rx_ant = phy->antenna_mask;
1887+
*tx_ant = 0;
1888+
for (i = 0; i < ARRAY_SIZE(dev->phys); i++)
1889+
if (dev->phys[i] && dev->phys[i]->hw == hw)
1890+
*tx_ant |= dev->phys[i]->chainmask;
1891+
*rx_ant = *tx_ant;
18441892
mutex_unlock(&dev->mutex);
18451893

18461894
return 0;

0 commit comments

Comments
 (0)