diff mbox series

[v2,2/6] wifi: mt76: mt7925: fix the wrong link_idx when has p2p_device

Message ID 20250114020712.704254-2-sean.wang@kernel.org (mailing list archive)
State New
Headers show
Series [v2,1/6] Revert "wifi: mt76: mt7925: Update mt7925_mcu_uni_[tx,rx]_ba for MLO" | expand

Commit Message

Sean Wang Jan. 14, 2025, 2:07 a.m. UTC
From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

When the p2p device and MLO station concurrent, the p2p device
will occupy the wrong link_idx when the MLO secondary link is added.

Fixes: e38a82d25b08 ("wifi: mt76: connac: Extend mt76_connac_mcu_uni_add_dev for MLO")
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
v2: generate the patch based on the latest mt76 tree
---
 drivers/net/wireless/mediatek/mt76/mt76.h          |  1 +
 .../net/wireless/mediatek/mt76/mt76_connac_mcu.c   |  4 ++--
 drivers/net/wireless/mediatek/mt76/mt7925/main.c   | 14 ++++++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)

Comments

Felix Fietkau Jan. 18, 2025, 9:57 a.m. UTC | #1
On 14.01.25 03:07, sean.wang@kernel.org wrote:
> From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
> 
> When the p2p device and MLO station concurrent, the p2p device
> will occupy the wrong link_idx when the MLO secondary link is added.
> 
> Fixes: e38a82d25b08 ("wifi: mt76: connac: Extend mt76_connac_mcu_uni_add_dev for MLO")
> Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
> v2: generate the patch based on the latest mt76 tree
> ---
>   drivers/net/wireless/mediatek/mt76/mt76.h          |  1 +
>   .../net/wireless/mediatek/mt76/mt76_connac_mcu.c   |  4 ++--
>   drivers/net/wireless/mediatek/mt76/mt7925/main.c   | 14 ++++++++++----
>   3 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> index 2082e3904d76..502b76a40ca8 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> @@ -371,6 +376,7 @@ static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
>   	mconf->mt76.band_idx = 0xff;
>   	mconf->mt76.wmm_idx = ieee80211_vif_is_mld(vif) ?
>   			      0 : mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
> +	mconf->mt76.link_idx = hweight16(mvif->valid_links);
>   
>   	if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
>   		mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4;

Why are you using hweight16 for the link idx? That doesn't make much 
sense to me. Shouldn't the actual link id be passed here, or is that 
index used in some other way?

- Felix
Mingyen Hsieh (謝明諺) Jan. 20, 2025, 2:09 a.m. UTC | #2
On Sat, 2025-01-18 at 10:57 +0100, Felix Fietkau wrote:
> 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> On 14.01.25 03:07, sean.wang@kernel.org wrote:
> > From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
> > 
> > When the p2p device and MLO station concurrent, the p2p device
> > will occupy the wrong link_idx when the MLO secondary link is
> > added.
> > 
> > Fixes: e38a82d25b08 ("wifi: mt76: connac: Extend
> > mt76_connac_mcu_uni_add_dev for MLO")
> > Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> > v2: generate the patch based on the latest mt76 tree
> > ---
> >   drivers/net/wireless/mediatek/mt76/mt76.h          |  1 +
> >   .../net/wireless/mediatek/mt76/mt76_connac_mcu.c   |  4 ++--
> >   drivers/net/wireless/mediatek/mt76/mt7925/main.c   | 14
> > ++++++++++----
> >   3 files changed, 13 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> > b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> > index 2082e3904d76..502b76a40ca8 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
> > @@ -371,6 +376,7 @@ static int mt7925_mac_link_bss_add(struct
> > mt792x_dev *dev,
> >       mconf->mt76.band_idx = 0xff;
> >       mconf->mt76.wmm_idx = ieee80211_vif_is_mld(vif) ?
> >                             0 : mconf->mt76.idx %
> > MT76_CONNAC_MAX_WMM_SETS;
> > +     mconf->mt76.link_idx = hweight16(mvif->valid_links);
> > 
> >       if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
> >               mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL
> > + 4;
> 
> Why are you using hweight16 for the link idx? That doesn't make much
> sense to me. Shouldn't the actual link id be passed here, or is that
> index used in some other way?
> 
> - Felix

Hi Felix,

The link_idx tells firmware which link index this is for the MLD, and
it different from link_id. Therefore, each time a link is added,
regardless of link_id, link_idx needs to be incremented by 1.

- Yen
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 132148f7b107..05651efb549e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -769,6 +769,7 @@  struct mt76_testmode_data {
 
 struct mt76_vif_link {
 	u8 idx;
+	u8 link_idx;
 	u8 omac_idx;
 	u8 band_idx;
 	u8 wmm_idx;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index f30cf9e71610..d0e49d68c5db 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -1168,7 +1168,7 @@  int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy,
 			.tag = cpu_to_le16(DEV_INFO_ACTIVE),
 			.len = cpu_to_le16(sizeof(struct req_tlv)),
 			.active = enable,
-			.link_idx = mvif->idx,
+			.link_idx = mvif->link_idx,
 		},
 	};
 	struct {
@@ -1191,7 +1191,7 @@  int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy,
 			.bmc_tx_wlan_idx = cpu_to_le16(wcid->idx),
 			.sta_idx = cpu_to_le16(wcid->idx),
 			.conn_state = 1,
-			.link_idx = mvif->idx,
+			.link_idx = mvif->link_idx,
 		},
 	};
 	int err, idx, cmd, len;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 2082e3904d76..502b76a40ca8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -360,10 +360,15 @@  static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
 	struct mt76_txq *mtxq;
 	int idx, ret = 0;
 
-	mconf->mt76.idx = __ffs64(~dev->mt76.vif_mask);
-	if (mconf->mt76.idx >= MT792x_MAX_INTERFACES) {
-		ret = -ENOSPC;
-		goto out;
+	if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
+		mconf->mt76.idx = MT792x_MAX_INTERFACES;
+	} else {
+		mconf->mt76.idx = __ffs64(~dev->mt76.vif_mask);
+
+		if (mconf->mt76.idx >= MT792x_MAX_INTERFACES) {
+			ret = -ENOSPC;
+			goto out;
+		}
 	}
 
 	mconf->mt76.omac_idx = ieee80211_vif_is_mld(vif) ?
@@ -371,6 +376,7 @@  static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
 	mconf->mt76.band_idx = 0xff;
 	mconf->mt76.wmm_idx = ieee80211_vif_is_mld(vif) ?
 			      0 : mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
+	mconf->mt76.link_idx = hweight16(mvif->valid_links);
 
 	if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
 		mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4;