* [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
@ 2025-03-08 15:35 Shengyu Qu
2025-03-10 0:33 ` Ping-Ke Shih
0 siblings, 1 reply; 8+ messages in thread
From: Shengyu Qu @ 2025-03-08 15:35 UTC (permalink / raw)
To: nbd, lorenzo, ryder.lee, shayne.chen, sean.wang, pkshih, johannes,
matthias.bgg, angelogioacchino.delregno, miriam.rachel.korenblit,
howard-yh.hsu, greearb, chui-hao.chiu, mingyen.hsieh, quic_adisi,
sujuan.chen, gustavoars, bo.jiao, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: Shengyu Qu
The current WED only supports 256 wcid, whereas mt7986 can support up to
512 entries, so firmware provides a rule to get sta_info by DA when wcid
is set to 0x3ff by txd. Also, WED provides a register to overwrite txd
wcid, that is, wcid[9:8] can be overwritten by 0x3 and wcid[7:0] is set
to 0xff by host driver.
However, firmware is unable to get sta_info from DA as DA != RA for
4addr cases, so firmware and wifi host driver both use wcid (256 - 271)
and (768 ~ 783) for sync up to get correct sta_info.
Currently WDS+WED config is completely broken on MT7986/7981 devices if
without this patch.
Tested-by: Sujuan Chen <sujuan.chen@mediatek.com>
Co-developed-by: Bo Jiao <bo.jiao@mediatek.com>
Signed-off-by: Bo Jiao <bo.jiao@mediatek.com>
Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
Signed-off-by: Shengyu Qu <wiagn233@outlook.com>
---
For unknown reason, the v9 patch has added a strange include header,
causing it fail to compile. So I resent it with that include removed.
Changes since v1:
- Drop duplicate setting in mmio
- Reduce the patch size by redefining mt76_wcid_alloc
Changes since v2:
- Rework wds wcid getting flow
Changes since v3:
- Rebase to next-20240703
- Sync with downstream patch
Changes since v4:
- Rebase to next-20240802
Changes since v5:
- Fixed build test error reported by robot
- Rebase to next-20240805
Changes since v6:
- Fix potential race conditions on tx/rx packets during the transition
- Rebase to Felix's newest codebase
Changes since v7:
- Fix build fail
Changes since v8:
- Changed code as Shih advised
---
drivers/net/wireless/mediatek/mt76/mt76.h | 9 ++++
.../net/wireless/mediatek/mt76/mt7915/main.c | 50 +++++++++++++++++--
.../net/wireless/mediatek/mt76/mt7915/mcu.c | 18 +++++--
.../net/wireless/mediatek/mt76/mt7915/mcu.h | 1 +
drivers/net/wireless/mediatek/mt76/util.c | 37 ++++++++++++--
drivers/net/wireless/mediatek/mt76/util.h | 7 ++-
6 files changed, 111 insertions(+), 11 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 132148f7b107..638ee9fae0c7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -28,6 +28,9 @@
#define MT76_TOKEN_FREE_THR 64
+#define MT76_WED_WDS_MIN 256
+#define MT76_WED_WDS_MAX 272
+
#define MT_QFLAG_WED_RING GENMASK(1, 0)
#define MT_QFLAG_WED_TYPE GENMASK(4, 2)
#define MT_QFLAG_WED BIT(5)
@@ -73,6 +76,12 @@ enum mt76_wed_type {
MT76_WED_RRO_Q_IND,
};
+enum mt76_wed_state {
+ MT76_WED_DEFAULT,
+ MT76_WED_ACTIVE,
+ MT76_WED_WDS_ACTIVE,
+};
+
struct mt76_bus_ops {
u32 (*rr)(struct mt76_dev *dev, u32 offset);
void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 3aa31c5cefa6..9be5937727cb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -745,8 +745,15 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
bool ext_phy = mvif->phy != &dev->phy;
int idx;
+ u8 flags = MT76_WED_DEFAULT;
- idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
+ !is_mt7915(&dev->mt76)) {
+ flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
+ MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
+ }
+
+ idx = __mt76_wcid_alloc(mdev->wcid_mask, MT7915_WTBL_STA, flags);
if (idx < 0)
return -ENOSPC;
@@ -1271,6 +1278,11 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
{
struct mt7915_dev *dev = mt7915_hw_dev(hw);
struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+ int min = MT76_WED_WDS_MIN, max = MT76_WED_WDS_MAX;
+ struct ieee80211_sta *pre_sta;
+ struct mt7915_sta *pre_msta;
+ u8 flags = MT76_WED_DEFAULT;
+ int tmp_idx;
if (enabled)
set_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
@@ -1280,6 +1292,34 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
if (!msta->wcid.sta)
return;
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
+ !is_mt7915(&dev->mt76) &&
+ (msta->wcid.idx < min || msta->wcid.idx > max - 1)) {
+ pre_sta = kmemdup(sta, sizeof(*sta) + sizeof(*msta), GFP_KERNEL | __GFP_ZERO);
+ pre_msta = (struct mt7915_sta *)pre_sta->drv_priv;
+
+ flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
+ MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
+
+ tmp_idx = __mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA, flags);
+ if (tmp_idx == -1)
+ goto error;
+ pre_msta->wcid.idx = (u16)tmp_idx;
+ mt7915_mac_sta_add(&dev->mt76, vif, pre_sta);
+ rcu_assign_pointer(dev->mt76.wcid[tmp_idx], &msta->wcid);
+
+ tmp_idx = msta->wcid.idx;
+ msta->wcid.idx = pre_msta->wcid.idx;
+ pre_msta->wcid.idx = (u16)tmp_idx;
+ rcu_assign_pointer(dev->mt76.wcid[tmp_idx], NULL);
+
+ synchronize_rcu();
+ mt7915_mac_sta_remove(&dev->mt76, vif, pre_sta);
+
+error:
+ kfree(pre_sta);
+ }
+
mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
}
@@ -1726,15 +1766,19 @@ mt7915_net_fill_forward_path(struct ieee80211_hw *hw,
if (!mtk_wed_device_active(wed))
return -ENODEV;
- if (msta->wcid.idx > 0xff)
+ if (msta->wcid.idx > MT7915_WTBL_STA)
return -EIO;
path->type = DEV_PATH_MTK_WDMA;
path->dev = ctx->dev;
path->mtk_wdma.wdma_idx = wed->wdma_idx;
path->mtk_wdma.bss = mvif->mt76.idx;
- path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? msta->wcid.idx : 0x3ff;
path->mtk_wdma.queue = phy != &dev->phy;
+ if (test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ||
+ is_mt7915(&dev->mt76))
+ path->mtk_wdma.wcid = msta->wcid.idx;
+ else
+ path->mtk_wdma.wcid = 0x3ff;
ctx->dev = NULL;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 9d790f234e82..32c5aa1a361e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -2385,10 +2385,20 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
mt76_connac_mcu_del_wtbl_all(&dev->mt76);
- if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
- is_mt7915(&dev->mt76)) ||
- !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
- mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
+#ifdef CONFIG_NET_MEDIATEK_SOC_WED
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
+ if (is_mt7915(&dev->mt76) ||
+ !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
+ ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
+ 0, 0, 0);
+ else
+ ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
+ MCU_WA_PARAM_WED_VERSION,
+ dev->mt76.mmio.wed.rev_id, 0);
+ if (ret)
+ return ret;
+ }
+#endif
ret = mt7915_mcu_set_mwds(dev, 1);
if (ret)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
index 49476a4182fd..c3dd0cb4a5d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
@@ -278,6 +278,7 @@ enum {
MCU_WA_PARAM_PDMA_RX = 0x04,
MCU_WA_PARAM_CPU_UTIL = 0x0b,
MCU_WA_PARAM_RED = 0x0e,
+ MCU_WA_PARAM_WED_VERSION = 0x32,
MCU_WA_PARAM_RED_SETTING = 0x40,
};
diff --git a/drivers/net/wireless/mediatek/mt76/util.c b/drivers/net/wireless/mediatek/mt76/util.c
index 95b3dc96e4c4..7fac9c79ebdf 100644
--- a/drivers/net/wireless/mediatek/mt76/util.c
+++ b/drivers/net/wireless/mediatek/mt76/util.c
@@ -42,9 +42,11 @@ bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
}
EXPORT_SYMBOL_GPL(____mt76_poll_msec);
-int mt76_wcid_alloc(u32 *mask, int size)
+int __mt76_wcid_alloc(u32 *mask, int size, u8 flag)
{
int i, idx = 0, cur;
+ int min = MT76_WED_WDS_MIN;
+ int max = MT76_WED_WDS_MAX;
for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
idx = ffs(~mask[i]);
@@ -53,16 +55,45 @@ int mt76_wcid_alloc(u32 *mask, int size)
idx--;
cur = i * 32 + idx;
- if (cur >= size)
+
+ switch (flag) {
+ case MT76_WED_ACTIVE:
+ if (cur >= min && cur < max)
+ continue;
+
+ if (cur >= size) {
+ u32 end = max - min - 1;
+
+ i = min / 32;
+ idx = ffs(~mask[i] & GENMASK(end, 0));
+ if (!idx)
+ goto error;
+ idx--;
+ cur = min + idx;
+ }
+
break;
+ case MT76_WED_WDS_ACTIVE:
+ if (cur < min)
+ continue;
+ if (cur >= max)
+ goto error;
+
+ break;
+ default:
+ if (cur >= size)
+ goto error;
+ break;
+ }
mask[i] |= BIT(idx);
return cur;
}
+error:
return -1;
}
-EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
+EXPORT_SYMBOL_GPL(__mt76_wcid_alloc);
int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx)
{
diff --git a/drivers/net/wireless/mediatek/mt76/util.h b/drivers/net/wireless/mediatek/mt76/util.h
index 260965dde94c..99b7263c0a20 100644
--- a/drivers/net/wireless/mediatek/mt76/util.h
+++ b/drivers/net/wireless/mediatek/mt76/util.h
@@ -27,7 +27,12 @@ enum {
#define MT76_INCR(_var, _size) \
(_var = (((_var) + 1) % (_size)))
-int mt76_wcid_alloc(u32 *mask, int size);
+int __mt76_wcid_alloc(u32 *mask, int size, u8 flags);
+
+static inline int mt76_wcid_alloc(u32 *mask, int size)
+{
+ return __mt76_wcid_alloc(mask, size, 0);
+}
static inline void
mt76_wcid_mask_set(u32 *mask, int idx)
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-08 15:35 [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled Shengyu Qu
@ 2025-03-10 0:33 ` Ping-Ke Shih
2025-03-10 10:33 ` Shengyu Qu
0 siblings, 1 reply; 8+ messages in thread
From: Ping-Ke Shih @ 2025-03-10 0:33 UTC (permalink / raw)
To: Shengyu Qu, nbd@nbd.name, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Shengyu Qu <wiagn233@outlook.com> wrote:
> @@ -1280,6 +1292,34 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
> if (!msta->wcid.sta)
> return;
>
> + if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
> + !is_mt7915(&dev->mt76) &&
> + (msta->wcid.idx < min || msta->wcid.idx > max - 1)) {
> + pre_sta = kmemdup(sta, sizeof(*sta) + sizeof(*msta), GFP_KERNEL | __GFP_ZERO);
Need to check if pre_sta != NULL before using.
> + pre_msta = (struct mt7915_sta *)pre_sta->drv_priv;
> +
> + flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
> + MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
> +
> + tmp_idx = __mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA, flags);
> + if (tmp_idx == -1)
At other places, it checks this by 'idx < 0'.
> + goto error;
> + pre_msta->wcid.idx = (u16)tmp_idx;
> + mt7915_mac_sta_add(&dev->mt76, vif, pre_sta);
> + rcu_assign_pointer(dev->mt76.wcid[tmp_idx], &msta->wcid);
> +
> + tmp_idx = msta->wcid.idx;
> + msta->wcid.idx = pre_msta->wcid.idx;
> + pre_msta->wcid.idx = (u16)tmp_idx;
> + rcu_assign_pointer(dev->mt76.wcid[tmp_idx], NULL);
> +
> + synchronize_rcu();
> + mt7915_mac_sta_remove(&dev->mt76, vif, pre_sta);
> +
> +error:
> + kfree(pre_sta);
> + }
> +
> mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
> }
>
[...]
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> index 9d790f234e82..32c5aa1a361e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> @@ -2385,10 +2385,20 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
>
> mt76_connac_mcu_del_wtbl_all(&dev->mt76);
>
> - if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
> - is_mt7915(&dev->mt76)) ||
> - !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
> - mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
> +#ifdef CONFIG_NET_MEDIATEK_SOC_WED
if (IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED) ... ?
> + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
> + if (is_mt7915(&dev->mt76) ||
> + !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
> + 0, 0, 0);
> + else
> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
> + MCU_WA_PARAM_WED_VERSION,
> + dev->mt76.mmio.wed.rev_id, 0);
> + if (ret)
> + return ret;
> + }
> +#endif
>
> ret = mt7915_mcu_set_mwds(dev, 1);
> if (ret)
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
> b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
> index 49476a4182fd..c3dd0cb4a5d3 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
> @@ -278,6 +278,7 @@ enum {
> MCU_WA_PARAM_PDMA_RX = 0x04,
> MCU_WA_PARAM_CPU_UTIL = 0x0b,
> MCU_WA_PARAM_RED = 0x0e,
> + MCU_WA_PARAM_WED_VERSION = 0x32,
> MCU_WA_PARAM_RED_SETTING = 0x40,
> };
>
> diff --git a/drivers/net/wireless/mediatek/mt76/util.c b/drivers/net/wireless/mediatek/mt76/util.c
> index 95b3dc96e4c4..7fac9c79ebdf 100644
> --- a/drivers/net/wireless/mediatek/mt76/util.c
> +++ b/drivers/net/wireless/mediatek/mt76/util.c
> @@ -42,9 +42,11 @@ bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
> }
> EXPORT_SYMBOL_GPL(____mt76_poll_msec);
>
> -int mt76_wcid_alloc(u32 *mask, int size)
> +int __mt76_wcid_alloc(u32 *mask, int size, u8 flag)
> {
> int i, idx = 0, cur;
> + int min = MT76_WED_WDS_MIN;
> + int max = MT76_WED_WDS_MAX;
In reverse X'mas tree order?
>
> for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
> idx = ffs(~mask[i]);
> @@ -53,16 +55,45 @@ int mt76_wcid_alloc(u32 *mask, int size)
>
> idx--;
> cur = i * 32 + idx;
> - if (cur >= size)
> +
> + switch (flag) {
> + case MT76_WED_ACTIVE:
> + if (cur >= min && cur < max)
> + continue;
> +
> + if (cur >= size) {
> + u32 end = max - min - 1;
> +
> + i = min / 32;
> + idx = ffs(~mask[i] & GENMASK(end, 0));
> + if (!idx)
> + goto error;
> + idx--;
> + cur = min + idx;
> + }
> +
> break;
> + case MT76_WED_WDS_ACTIVE:
> + if (cur < min)
> + continue;
> + if (cur >= max)
> + goto error;
> +
> + break;
> + default:
> + if (cur >= size)
> + goto error;
> + break;
> + }
>
> mask[i] |= BIT(idx);
> return cur;
> }
>
> +error:
> return -1;
> }
> -EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
> +EXPORT_SYMBOL_GPL(__mt76_wcid_alloc);
>
> int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx)
> {
> diff --git a/drivers/net/wireless/mediatek/mt76/util.h b/drivers/net/wireless/mediatek/mt76/util.h
> index 260965dde94c..99b7263c0a20 100644
> --- a/drivers/net/wireless/mediatek/mt76/util.h
> +++ b/drivers/net/wireless/mediatek/mt76/util.h
> @@ -27,7 +27,12 @@ enum {
> #define MT76_INCR(_var, _size) \
> (_var = (((_var) + 1) % (_size)))
>
> -int mt76_wcid_alloc(u32 *mask, int size);
> +int __mt76_wcid_alloc(u32 *mask, int size, u8 flags);
> +
> +static inline int mt76_wcid_alloc(u32 *mask, int size)
> +{
> + return __mt76_wcid_alloc(mask, size, 0);
return __mt76_wcid_alloc(mask, size, MT76_WED_DEFAULT); ?
> +}
>
> static inline void
> mt76_wcid_mask_set(u32 *mask, int idx)
> --
> 2.48.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-10 0:33 ` Ping-Ke Shih
@ 2025-03-10 10:33 ` Shengyu Qu
2025-03-10 10:41 ` Felix Fietkau
0 siblings, 1 reply; 8+ messages in thread
From: Shengyu Qu @ 2025-03-10 10:33 UTC (permalink / raw)
To: Ping-Ke Shih, nbd@nbd.name, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Cc: wiagn233
[-- Attachment #1.1.1: Type: text/plain, Size: 7308 bytes --]
在 2025/3/10 8:33, Ping-Ke Shih 写道:
> Shengyu Qu <wiagn233@outlook.com> wrote:
>> @@ -1280,6 +1292,34 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
>> if (!msta->wcid.sta)
>> return;
>>
>> + if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
>> + !is_mt7915(&dev->mt76) &&
>> + (msta->wcid.idx < min || msta->wcid.idx > max - 1)) {
>> + pre_sta = kmemdup(sta, sizeof(*sta) + sizeof(*msta), GFP_KERNEL | __GFP_ZERO);
>
> Need to check if pre_sta != NULL before using.
Thanks, will fix.
>
>> + pre_msta = (struct mt7915_sta *)pre_sta->drv_priv;
>> +
>> + flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
>> + MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
>> +
>> + tmp_idx = __mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA, flags);
>> + if (tmp_idx == -1)
>
> At other places, it checks this by 'idx < 0'.
Will fix.
>
>> + goto error;
>> + pre_msta->wcid.idx = (u16)tmp_idx;
>> + mt7915_mac_sta_add(&dev->mt76, vif, pre_sta);
>> + rcu_assign_pointer(dev->mt76.wcid[tmp_idx], &msta->wcid);
>> +
>> + tmp_idx = msta->wcid.idx;
>> + msta->wcid.idx = pre_msta->wcid.idx;
>> + pre_msta->wcid.idx = (u16)tmp_idx;
>> + rcu_assign_pointer(dev->mt76.wcid[tmp_idx], NULL);
>> +
>> + synchronize_rcu();
>> + mt7915_mac_sta_remove(&dev->mt76, vif, pre_sta);
>> +
>> +error:
>> + kfree(pre_sta);
>> + }
>> +
>> mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
>> }
>>
>
> [...]
>
>> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> index 9d790f234e82..32c5aa1a361e 100644
>> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> @@ -2385,10 +2385,20 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
>>
>> mt76_connac_mcu_del_wtbl_all(&dev->mt76);
>>
>> - if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
>> - is_mt7915(&dev->mt76)) ||
>> - !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
>> - mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
>> +#ifdef CONFIG_NET_MEDIATEK_SOC_WED
>
> if (IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED) ... ?
I did a search in code about this, seems current MT76 code is using a
mix of IS_ENABLED and ifdef. And this file already have a ifdef
implementation. I prefer keep it as is and use another patch to convert
the whole mt76 driver.
>
>> + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
>> + if (is_mt7915(&dev->mt76) ||
>> + !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
>> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
>> + 0, 0, 0);
>> + else
>> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
>> + MCU_WA_PARAM_WED_VERSION,
>> + dev->mt76.mmio.wed.rev_id, 0);
>> + if (ret)
>> + return ret;
>> + }
>> +#endif
>>
>> ret = mt7915_mcu_set_mwds(dev, 1);
>> if (ret)
>> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
>> b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
>> index 49476a4182fd..c3dd0cb4a5d3 100644
>> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
>> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
>> @@ -278,6 +278,7 @@ enum {
>> MCU_WA_PARAM_PDMA_RX = 0x04,
>> MCU_WA_PARAM_CPU_UTIL = 0x0b,
>> MCU_WA_PARAM_RED = 0x0e,
>> + MCU_WA_PARAM_WED_VERSION = 0x32,
>> MCU_WA_PARAM_RED_SETTING = 0x40,
>> };
>>
>> diff --git a/drivers/net/wireless/mediatek/mt76/util.c b/drivers/net/wireless/mediatek/mt76/util.c
>> index 95b3dc96e4c4..7fac9c79ebdf 100644
>> --- a/drivers/net/wireless/mediatek/mt76/util.c
>> +++ b/drivers/net/wireless/mediatek/mt76/util.c
>> @@ -42,9 +42,11 @@ bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
>> }
>> EXPORT_SYMBOL_GPL(____mt76_poll_msec);
>>
>> -int mt76_wcid_alloc(u32 *mask, int size)
>> +int __mt76_wcid_alloc(u32 *mask, int size, u8 flag)
>> {
>> int i, idx = 0, cur;
>> + int min = MT76_WED_WDS_MIN;
>> + int max = MT76_WED_WDS_MAX;
>
> In reverse X'mas tree order?
Will fix.
>
>>
>> for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
>> idx = ffs(~mask[i]);
>> @@ -53,16 +55,45 @@ int mt76_wcid_alloc(u32 *mask, int size)
>>
>> idx--;
>> cur = i * 32 + idx;
>> - if (cur >= size)
>> +
>> + switch (flag) {
>> + case MT76_WED_ACTIVE:
>> + if (cur >= min && cur < max)
>> + continue;
>> +
>> + if (cur >= size) {
>> + u32 end = max - min - 1;
>> +
>> + i = min / 32;
>> + idx = ffs(~mask[i] & GENMASK(end, 0));
>> + if (!idx)
>> + goto error;
>> + idx--;
>> + cur = min + idx;
>> + }
>> +
>> break;
>> + case MT76_WED_WDS_ACTIVE:
>> + if (cur < min)
>> + continue;
>> + if (cur >= max)
>> + goto error;
>> +
>> + break;
>> + default:
>> + if (cur >= size)
>> + goto error;
>> + break;
>> + }
>>
>> mask[i] |= BIT(idx);
>> return cur;
>> }
>>
>> +error:
>> return -1;
>> }
>> -EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
>> +EXPORT_SYMBOL_GPL(__mt76_wcid_alloc);
>>
>> int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx)
>> {
>> diff --git a/drivers/net/wireless/mediatek/mt76/util.h b/drivers/net/wireless/mediatek/mt76/util.h
>> index 260965dde94c..99b7263c0a20 100644
>> --- a/drivers/net/wireless/mediatek/mt76/util.h
>> +++ b/drivers/net/wireless/mediatek/mt76/util.h
>> @@ -27,7 +27,12 @@ enum {
>> #define MT76_INCR(_var, _size) \
>> (_var = (((_var) + 1) % (_size)))
>>
>> -int mt76_wcid_alloc(u32 *mask, int size);
>> +int __mt76_wcid_alloc(u32 *mask, int size, u8 flags);
>> +
>> +static inline int mt76_wcid_alloc(u32 *mask, int size)
>> +{
>> + return __mt76_wcid_alloc(mask, size, 0);
>
> return __mt76_wcid_alloc(mask, size, MT76_WED_DEFAULT); ?
Will fix.
>
>> +}
>>
>> static inline void
>> mt76_wcid_mask_set(u32 *mask, int idx)
>> --
>> 2.48.1
>
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 6977 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-10 10:33 ` Shengyu Qu
@ 2025-03-10 10:41 ` Felix Fietkau
2025-03-10 12:41 ` Shengyu Qu
0 siblings, 1 reply; 8+ messages in thread
From: Felix Fietkau @ 2025-03-10 10:41 UTC (permalink / raw)
To: Shengyu Qu, Ping-Ke Shih, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
On 10.03.25 11:33, Shengyu Qu wrote:
>> if (IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED) ... ?
> I did a search in code about this, seems current MT76 code is using a
> mix of IS_ENABLED and ifdef. And this file already have a ifdef
> implementation. I prefer keep it as is and use another patch to convert
> the whole mt76 driver.
The driver uses #ifdef where it relies on struct members that are also
#ifdef'd out, and using IS_ENABLED would lead do build failures.
- Felix
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-10 10:41 ` Felix Fietkau
@ 2025-03-10 12:41 ` Shengyu Qu
2025-03-11 0:47 ` Ping-Ke Shih
0 siblings, 1 reply; 8+ messages in thread
From: Shengyu Qu @ 2025-03-10 12:41 UTC (permalink / raw)
To: Felix Fietkau, Ping-Ke Shih, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Cc: wiagn233
[-- Attachment #1.1.1: Type: text/plain, Size: 8822 bytes --]
Hello,
I modified the patch as you two adviced. If you think it's ok, please
tell me and I'll send a v10 patch.
Modified patch is attached below.
Best regards,
Shengyu
---
drivers/net/wireless/mediatek/mt76/mt76.h | 15 ++++++
.../net/wireless/mediatek/mt76/mt7915/main.c | 53 +++++++++++++++++--
.../net/wireless/mediatek/mt76/mt7915/mcu.c | 18 +++++--
.../net/wireless/mediatek/mt76/mt7915/mcu.h | 1 +
drivers/net/wireless/mediatek/mt76/util.c | 37 +++++++++++--
drivers/net/wireless/mediatek/mt76/util.h | 2 +-
6 files changed, 115 insertions(+), 11 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 132148f7b107..bd943b8b20bc 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -28,6 +28,9 @@
#define MT76_TOKEN_FREE_THR 64
+#define MT76_WED_WDS_MIN 256
+#define MT76_WED_WDS_MAX 272
+
#define MT_QFLAG_WED_RING GENMASK(1, 0)
#define MT_QFLAG_WED_TYPE GENMASK(4, 2)
#define MT_QFLAG_WED BIT(5)
@@ -73,6 +76,12 @@ enum mt76_wed_type {
MT76_WED_RRO_Q_IND,
};
+enum mt76_wed_state {
+ MT76_WED_DEFAULT,
+ MT76_WED_ACTIVE,
+ MT76_WED_WDS_ACTIVE,
+};
+
struct mt76_bus_ops {
u32 (*rr)(struct mt76_dev *dev, u32 offset);
void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
@@ -1165,6 +1174,12 @@ void mt76_wed_dma_reset(struct mt76_dev *dev);
int mt76_wed_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct net_device *netdev, enum tc_setup_type type,
void *type_data);
+
+static inline int mt76_wcid_alloc(u32 *mask, int size)
+{
+ return __mt76_wcid_alloc(mask, size, MT76_WED_DEFAULT);
+}
+
#ifdef CONFIG_NET_MEDIATEK_SOC_WED
u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size);
int mt76_wed_offload_enable(struct mtk_wed_device *wed);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 3aa31c5cefa6..07c2ce518d97 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -745,8 +745,15 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
bool ext_phy = mvif->phy != &dev->phy;
int idx;
+ u8 flags = MT76_WED_DEFAULT;
- idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
+ !is_mt7915(&dev->mt76)) {
+ flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
+ MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
+ }
+
+ idx = __mt76_wcid_alloc(mdev->wcid_mask, MT7915_WTBL_STA, flags);
if (idx < 0)
return -ENOSPC;
@@ -1271,6 +1278,11 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
{
struct mt7915_dev *dev = mt7915_hw_dev(hw);
struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+ int min = MT76_WED_WDS_MIN, max = MT76_WED_WDS_MAX;
+ struct ieee80211_sta *pre_sta;
+ struct mt7915_sta *pre_msta;
+ u8 flags = MT76_WED_DEFAULT;
+ int tmp_idx;
if (enabled)
set_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
@@ -1280,6 +1292,37 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
if (!msta->wcid.sta)
return;
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
+ !is_mt7915(&dev->mt76) &&
+ (msta->wcid.idx < min || msta->wcid.idx > max - 1)) {
+ pre_sta = kmemdup(sta, sizeof(*sta) + sizeof(*msta), GFP_KERNEL | __GFP_ZERO);
+ if (pre_sta == NULL)
+ goto error_alloc;
+ pre_msta = (struct mt7915_sta *)pre_sta->drv_priv;
+
+ flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
+ MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
+
+ tmp_idx = __mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA, flags);
+ if (tmp_idx < 0)
+ goto error_wcid;
+ pre_msta->wcid.idx = (u16)tmp_idx;
+ mt7915_mac_sta_add(&dev->mt76, vif, pre_sta);
+ rcu_assign_pointer(dev->mt76.wcid[tmp_idx], &msta->wcid);
+
+ tmp_idx = msta->wcid.idx;
+ msta->wcid.idx = pre_msta->wcid.idx;
+ pre_msta->wcid.idx = (u16)tmp_idx;
+ rcu_assign_pointer(dev->mt76.wcid[tmp_idx], NULL);
+
+ synchronize_rcu();
+ mt7915_mac_sta_remove(&dev->mt76, vif, pre_sta);
+
+error_wcid:
+ kfree(pre_sta);
+ }
+
+error_alloc:
mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
}
@@ -1726,15 +1769,19 @@ mt7915_net_fill_forward_path(struct ieee80211_hw *hw,
if (!mtk_wed_device_active(wed))
return -ENODEV;
- if (msta->wcid.idx > 0xff)
+ if (msta->wcid.idx > MT7915_WTBL_STA)
return -EIO;
path->type = DEV_PATH_MTK_WDMA;
path->dev = ctx->dev;
path->mtk_wdma.wdma_idx = wed->wdma_idx;
path->mtk_wdma.bss = mvif->mt76.idx;
- path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? msta->wcid.idx : 0x3ff;
path->mtk_wdma.queue = phy != &dev->phy;
+ if (test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ||
+ is_mt7915(&dev->mt76))
+ path->mtk_wdma.wcid = msta->wcid.idx;
+ else
+ path->mtk_wdma.wcid = 0x3ff;
ctx->dev = NULL;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 9d790f234e82..191f966c3f32 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -2385,10 +2385,20 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
mt76_connac_mcu_del_wtbl_all(&dev->mt76);
- if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
- is_mt7915(&dev->mt76)) ||
- !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
- mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
+#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
+ if (is_mt7915(&dev->mt76) ||
+ !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
+ ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
+ 0, 0, 0);
+ else
+ ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
+ MCU_WA_PARAM_WED_VERSION,
+ dev->mt76.mmio.wed.rev_id, 0);
+ if (ret)
+ return ret;
+ }
+#endif
ret = mt7915_mcu_set_mwds(dev, 1);
if (ret)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
index 49476a4182fd..c3dd0cb4a5d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
@@ -278,6 +278,7 @@ enum {
MCU_WA_PARAM_PDMA_RX = 0x04,
MCU_WA_PARAM_CPU_UTIL = 0x0b,
MCU_WA_PARAM_RED = 0x0e,
+ MCU_WA_PARAM_WED_VERSION = 0x32,
MCU_WA_PARAM_RED_SETTING = 0x40,
};
diff --git a/drivers/net/wireless/mediatek/mt76/util.c b/drivers/net/wireless/mediatek/mt76/util.c
index 95b3dc96e4c4..e80bef2b33a1 100644
--- a/drivers/net/wireless/mediatek/mt76/util.c
+++ b/drivers/net/wireless/mediatek/mt76/util.c
@@ -42,8 +42,10 @@ bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
}
EXPORT_SYMBOL_GPL(____mt76_poll_msec);
-int mt76_wcid_alloc(u32 *mask, int size)
+int __mt76_wcid_alloc(u32 *mask, int size, u8 flag)
{
+ int max = MT76_WED_WDS_MAX;
+ int min = MT76_WED_WDS_MIN;
int i, idx = 0, cur;
for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
@@ -53,16 +55,45 @@ int mt76_wcid_alloc(u32 *mask, int size)
idx--;
cur = i * 32 + idx;
- if (cur >= size)
+
+ switch (flag) {
+ case MT76_WED_ACTIVE:
+ if (cur >= min && cur < max)
+ continue;
+
+ if (cur >= size) {
+ u32 end = max - min - 1;
+
+ i = min / 32;
+ idx = ffs(~mask[i] & GENMASK(end, 0));
+ if (!idx)
+ goto error;
+ idx--;
+ cur = min + idx;
+ }
+
break;
+ case MT76_WED_WDS_ACTIVE:
+ if (cur < min)
+ continue;
+ if (cur >= max)
+ goto error;
+
+ break;
+ default:
+ if (cur >= size)
+ goto error;
+ break;
+ }
mask[i] |= BIT(idx);
return cur;
}
+error:
return -1;
}
-EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
+EXPORT_SYMBOL_GPL(__mt76_wcid_alloc);
int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx)
{
diff --git a/drivers/net/wireless/mediatek/mt76/util.h b/drivers/net/wireless/mediatek/mt76/util.h
index 260965dde94c..fe95a847182e 100644
--- a/drivers/net/wireless/mediatek/mt76/util.h
+++ b/drivers/net/wireless/mediatek/mt76/util.h
@@ -27,7 +27,7 @@ enum {
#define MT76_INCR(_var, _size) \
(_var = (((_var) + 1) % (_size)))
-int mt76_wcid_alloc(u32 *mask, int size);
+int __mt76_wcid_alloc(u32 *mask, int size, u8 flags);
static inline void
mt76_wcid_mask_set(u32 *mask, int idx)
--
2.48.1
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 6977 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-10 12:41 ` Shengyu Qu
@ 2025-03-11 0:47 ` Ping-Ke Shih
2025-03-11 5:14 ` Shengyu Qu
0 siblings, 1 reply; 8+ messages in thread
From: Ping-Ke Shih @ 2025-03-11 0:47 UTC (permalink / raw)
To: Shengyu Qu, Felix Fietkau, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Shengyu Qu <wiagn233@outlook.com> wrote:
> Hello,
>
> I modified the patch as you two adviced. If you think it's ok, please
> tell me and I'll send a v10 patch.
>
> Modified patch is attached below.
Since you want people review whole patch, why not just sending v10?
>
> Best regards,
> Shengyu
>
> ---
> drivers/net/wireless/mediatek/mt76/mt76.h | 15 ++++++
> .../net/wireless/mediatek/mt76/mt7915/main.c | 53 +++++++++++++++++--
> .../net/wireless/mediatek/mt76/mt7915/mcu.c | 18 +++++--
> .../net/wireless/mediatek/mt76/mt7915/mcu.h | 1 +
> drivers/net/wireless/mediatek/mt76/util.c | 37 +++++++++++--
> drivers/net/wireless/mediatek/mt76/util.h | 2 +-
> 6 files changed, 115 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index 132148f7b107..bd943b8b20bc 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -28,6 +28,9 @@
>
> #define MT76_TOKEN_FREE_THR 64
>
> +#define MT76_WED_WDS_MIN 256
> +#define MT76_WED_WDS_MAX 272
> +
> #define MT_QFLAG_WED_RING GENMASK(1, 0)
> #define MT_QFLAG_WED_TYPE GENMASK(4, 2)
> #define MT_QFLAG_WED BIT(5)
> @@ -73,6 +76,12 @@ enum mt76_wed_type {
> MT76_WED_RRO_Q_IND,
> };
>
> +enum mt76_wed_state {
> + MT76_WED_DEFAULT,
> + MT76_WED_ACTIVE,
> + MT76_WED_WDS_ACTIVE,
> +};
> +
> struct mt76_bus_ops {
> u32 (*rr)(struct mt76_dev *dev, u32 offset);
> void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
> @@ -1165,6 +1174,12 @@ void mt76_wed_dma_reset(struct mt76_dev *dev);
> int mt76_wed_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> struct net_device *netdev, enum tc_setup_type type,
> void *type_data);
> +
> +static inline int mt76_wcid_alloc(u32 *mask, int size)
> +{
> + return __mt76_wcid_alloc(mask, size, MT76_WED_DEFAULT);
> +}
> +
> #ifdef CONFIG_NET_MEDIATEK_SOC_WED
> u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size);
> int mt76_wed_offload_enable(struct mtk_wed_device *wed);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> index 3aa31c5cefa6..07c2ce518d97 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> @@ -745,8 +745,15 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
> bool ext_phy = mvif->phy != &dev->phy;
> int idx;
> + u8 flags = MT76_WED_DEFAULT;
In reverse X'mas tree order.
>
> - idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
> + if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
> + !is_mt7915(&dev->mt76)) {
> + flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
> + MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
> + }
> +
> + idx = __mt76_wcid_alloc(mdev->wcid_mask, MT7915_WTBL_STA, flags);
> if (idx < 0)
> return -ENOSPC;
>
[...]
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> index 9d790f234e82..191f966c3f32 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> @@ -2385,10 +2385,20 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
>
> mt76_connac_mcu_del_wtbl_all(&dev->mt76);
>
> - if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
> - is_mt7915(&dev->mt76)) ||
> - !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
> - mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
> +#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
In MT76, there are two styles:
#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
#ifdef CONFIG_NET_MEDIATEK_SOC_WED
I think both are correct. Just wonder why not making them consistent.
> + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
> + if (is_mt7915(&dev->mt76) ||
> + !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
> + 0, 0, 0);
> + else
> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
> + MCU_WA_PARAM_WED_VERSION,
> + dev->mt76.mmio.wed.rev_id, 0);
> + if (ret)
> + return ret;
> + }
> +#endif
>
> ret = mt7915_mcu_set_mwds(dev, 1);
> if (ret)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-11 0:47 ` Ping-Ke Shih
@ 2025-03-11 5:14 ` Shengyu Qu
2025-03-11 8:29 ` Ping-Ke Shih
0 siblings, 1 reply; 8+ messages in thread
From: Shengyu Qu @ 2025-03-11 5:14 UTC (permalink / raw)
To: Ping-Ke Shih, Felix Fietkau, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Cc: wiagn233
[-- Attachment #1.1.1: Type: text/plain, Size: 4962 bytes --]
在 2025/3/11 8:47, Ping-Ke Shih 写道:
> Shengyu Qu <wiagn233@outlook.com> wrote:
>> Hello,
>>
>> I modified the patch as you two adviced. If you think it's ok, please
>> tell me and I'll send a v10 patch.
>>
>> Modified patch is attached below.
>
> Since you want people review whole patch, why not just sending v10?
OK, I'll send v10 after fixing the issue you mentioned.
>
>>
>> Best regards,
>> Shengyu
>>
>> ---
>> drivers/net/wireless/mediatek/mt76/mt76.h | 15 ++++++
>> .../net/wireless/mediatek/mt76/mt7915/main.c | 53 +++++++++++++++++--
>> .../net/wireless/mediatek/mt76/mt7915/mcu.c | 18 +++++--
>> .../net/wireless/mediatek/mt76/mt7915/mcu.h | 1 +
>> drivers/net/wireless/mediatek/mt76/util.c | 37 +++++++++++--
>> drivers/net/wireless/mediatek/mt76/util.h | 2 +-
>> 6 files changed, 115 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
>> index 132148f7b107..bd943b8b20bc 100644
>> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
>> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
>> @@ -28,6 +28,9 @@
>>
>> #define MT76_TOKEN_FREE_THR 64
>>
>> +#define MT76_WED_WDS_MIN 256
>> +#define MT76_WED_WDS_MAX 272
>> +
>> #define MT_QFLAG_WED_RING GENMASK(1, 0)
>> #define MT_QFLAG_WED_TYPE GENMASK(4, 2)
>> #define MT_QFLAG_WED BIT(5)
>> @@ -73,6 +76,12 @@ enum mt76_wed_type {
>> MT76_WED_RRO_Q_IND,
>> };
>>
>> +enum mt76_wed_state {
>> + MT76_WED_DEFAULT,
>> + MT76_WED_ACTIVE,
>> + MT76_WED_WDS_ACTIVE,
>> +};
>> +
>> struct mt76_bus_ops {
>> u32 (*rr)(struct mt76_dev *dev, u32 offset);
>> void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
>> @@ -1165,6 +1174,12 @@ void mt76_wed_dma_reset(struct mt76_dev *dev);
>> int mt76_wed_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
>> struct net_device *netdev, enum tc_setup_type type,
>> void *type_data);
>> +
>> +static inline int mt76_wcid_alloc(u32 *mask, int size)
>> +{
>> + return __mt76_wcid_alloc(mask, size, MT76_WED_DEFAULT);
>> +}
>> +
>> #ifdef CONFIG_NET_MEDIATEK_SOC_WED
>> u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size);
>> int mt76_wed_offload_enable(struct mtk_wed_device *wed);
>> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
>> b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
>> index 3aa31c5cefa6..07c2ce518d97 100644
>> --- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
>> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
>> @@ -745,8 +745,15 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
>> struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
>> bool ext_phy = mvif->phy != &dev->phy;
>> int idx;
>> + u8 flags = MT76_WED_DEFAULT;
>
> In reverse X'mas tree order.
Thanks, will fix.
>
>>
>> - idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
>> + if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
>> + !is_mt7915(&dev->mt76)) {
>> + flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
>> + MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
>> + }
>> +
>> + idx = __mt76_wcid_alloc(mdev->wcid_mask, MT7915_WTBL_STA, flags);
>> if (idx < 0)
>> return -ENOSPC;
>>
>
> [...]
>
>> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> index 9d790f234e82..191f966c3f32 100644
>> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
>> @@ -2385,10 +2385,20 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
>>
>> mt76_connac_mcu_del_wtbl_all(&dev->mt76);
>>
>> - if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
>> - is_mt7915(&dev->mt76)) ||
>> - !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
>> - mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
>> +#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
>
> In MT76, there are two styles:
> #if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
> #ifdef CONFIG_NET_MEDIATEK_SOC_WED
>
> I think both are correct. Just wonder why not making them consistent.
Seems you didn't receive Felix's email, check this:
https://lore.kernel.org/linux-wireless/71ed8398-4619-4793-804d-77cad36e7402@nbd.name/
>
>> + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
>> + if (is_mt7915(&dev->mt76) ||
>> + !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
>> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
>> + 0, 0, 0);
>> + else
>> + ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
>> + MCU_WA_PARAM_WED_VERSION,
>> + dev->mt76.mmio.wed.rev_id, 0);
>> + if (ret)
>> + return ret;
>> + }
>> +#endif
>>
>> ret = mt7915_mcu_set_mwds(dev, 1);
>> if (ret)
>
>
>
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 6977 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled
2025-03-11 5:14 ` Shengyu Qu
@ 2025-03-11 8:29 ` Ping-Ke Shih
0 siblings, 0 replies; 8+ messages in thread
From: Ping-Ke Shih @ 2025-03-11 8:29 UTC (permalink / raw)
To: Shengyu Qu, Felix Fietkau, lorenzo@kernel.org,
ryder.lee@mediatek.com, shayne.chen@mediatek.com,
sean.wang@mediatek.com, johannes@sipsolutions.net,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
miriam.rachel.korenblit@intel.com, howard-yh.hsu@mediatek.com,
greearb@candelatech.com, chui-hao.chiu@mediatek.com,
mingyen.hsieh@mediatek.com, quic_adisi@quicinc.com,
sujuan.chen@mediatek.com, gustavoars@kernel.org,
bo.jiao@mediatek.com, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
> >>
> >> mt76_connac_mcu_del_wtbl_all(&dev->mt76);
> >>
> >> - if ((mtk_wed_device_active(&dev->mt76.mmio.wed) &&
> >> - is_mt7915(&dev->mt76)) ||
> >> - !mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
> >> - mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
> >> +#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
> >
> > In MT76, there are two styles:
> > #if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
> > #ifdef CONFIG_NET_MEDIATEK_SOC_WED
> >
> > I think both are correct. Just wonder why not making them consistent.
> Seems you didn't receive Felix's email, check this:
> https://lore.kernel.org/linux-wireless/71ed8398-4619-4793-804d-77cad36e7402@nbd.name/
>
I was aware of this. Felix pointed out 'if (IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED))'
will lead build error. But what I mentioned here were '#if' and
'#ifdef' (preprocess directive).
Anyway, ignore this.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-03-11 8:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-08 15:35 [PATCH v9 RESEND] wifi: mt76: mt7915: add wds support when wed is enabled Shengyu Qu
2025-03-10 0:33 ` Ping-Ke Shih
2025-03-10 10:33 ` Shengyu Qu
2025-03-10 10:41 ` Felix Fietkau
2025-03-10 12:41 ` Shengyu Qu
2025-03-11 0:47 ` Ping-Ke Shih
2025-03-11 5:14 ` Shengyu Qu
2025-03-11 8:29 ` Ping-Ke Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox