linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mt76: mt7915: wed: find rx token by physical address
@ 2025-02-22 11:38 Shengyu Qu
  2025-03-11  8:51 ` Shengyu Qu
  0 siblings, 1 reply; 6+ messages in thread
From: Shengyu Qu @ 2025-02-22 11:38 UTC (permalink / raw)
  To: nbd, lorenzo, ryder.lee, shayne.chen, sean.wang, linux-wireless,
	linux-kernel, linux-arm-kernel, linux-mediatek
  Cc: johannes, matthias.bgg, angelogioacchino.delregno, Shengyu Qu,
	Peter Chiu

The token id in RxDMAD may be incorrect when it is not the last frame
due to WED HW bug. Lookup correct token id by physical address in sdp0.

Downstream patch link: https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/737340322ab22b138fd200e020d61ffdbe3e36a9/autobuild/autobuild_5.4_mac80211_release/mt7988_wifi7_mac80211_mlo/package/kernel/mt76/patches/0062-mtk-wifi-mt76-mt7915-wed-find-rx-token-by-physical-a.patch

Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Shengyu Qu <wiagn233@outlook.com>
---
 drivers/net/wireless/mediatek/mt76/dma.c | 25 +++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
index 844af16ee551..5bf63014263c 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -444,9 +444,32 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
 	mt76_dma_should_drop_buf(drop, ctrl, buf1, desc_info);
 
 	if (mt76_queue_is_wed_rx(q)) {
+		u32 id, find = 0;
 		u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1);
-		struct mt76_txwi_cache *t = mt76_rx_token_release(dev, token);
+		struct mt76_txwi_cache *t;
+
+		if (*more) {
+			spin_lock_bh(&dev->rx_token_lock);
+
+			idr_for_each_entry(&dev->rx_token, t, id) {
+				if (t->dma_addr == le32_to_cpu(desc->buf0)) {
+					find = 1;
+					token = id;
+
+					/* Write correct id back to DMA*/
+					u32p_replace_bits(&buf1, id,
+							  MT_DMA_CTL_TOKEN);
+					WRITE_ONCE(desc->buf1, cpu_to_le32(buf1));
+					break;
+				}
+			}
+
+			spin_unlock_bh(&dev->rx_token_lock);
+			if (!find)
+				return NULL;
+		}
 
+		t = mt76_rx_token_release(dev, token);
 		if (!t)
 			return NULL;
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] mt76: mt7915: wed: find rx token by physical address
  2025-02-22 11:38 [PATCH v1] mt76: mt7915: wed: find rx token by physical address Shengyu Qu
@ 2025-03-11  8:51 ` Shengyu Qu
       [not found]   ` <e144d2ffe9924d81a7b60f38cdcf516a@realtek.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Shengyu Qu @ 2025-03-11  8:51 UTC (permalink / raw)
  To: nbd, lorenzo, ryder.lee, shayne.chen, sean.wang, linux-wireless,
	linux-kernel, linux-arm-kernel, linux-mediatek, Ping-Ke Shih
  Cc: wiagn233, johannes, matthias.bgg, angelogioacchino.delregno,
	Peter Chiu


[-- Attachment #1.1.1: Type: text/plain, Size: 2164 bytes --]

Hi Shih,

Can you also give this patch a review? Seems I also need to convert to
reverse Xmas tree order for this patch, will do it in next version.

Best regards,
Shengyu

在 2025/2/22 19:38, Shengyu Qu 写道:
> The token id in RxDMAD may be incorrect when it is not the last frame
> due to WED HW bug. Lookup correct token id by physical address in sdp0.
> 
> Downstream patch link: https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/737340322ab22b138fd200e020d61ffdbe3e36a9/autobuild/autobuild_5.4_mac80211_release/mt7988_wifi7_mac80211_mlo/package/kernel/mt76/patches/0062-mtk-wifi-mt76-mt7915-wed-find-rx-token-by-physical-a.patch
> 
> Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
> Signed-off-by: Shengyu Qu <wiagn233@outlook.com>
> ---
>   drivers/net/wireless/mediatek/mt76/dma.c | 25 +++++++++++++++++++++++-
>   1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
> index 844af16ee551..5bf63014263c 100644
> --- a/drivers/net/wireless/mediatek/mt76/dma.c
> +++ b/drivers/net/wireless/mediatek/mt76/dma.c
> @@ -444,9 +444,32 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
>   	mt76_dma_should_drop_buf(drop, ctrl, buf1, desc_info);
>   
>   	if (mt76_queue_is_wed_rx(q)) {
> +		u32 id, find = 0;
>   		u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1);
> -		struct mt76_txwi_cache *t = mt76_rx_token_release(dev, token);
> +		struct mt76_txwi_cache *t;
> +
> +		if (*more) {
> +			spin_lock_bh(&dev->rx_token_lock);
> +
> +			idr_for_each_entry(&dev->rx_token, t, id) {
> +				if (t->dma_addr == le32_to_cpu(desc->buf0)) {
> +					find = 1;
> +					token = id;
> +
> +					/* Write correct id back to DMA*/
> +					u32p_replace_bits(&buf1, id,
> +							  MT_DMA_CTL_TOKEN);
> +					WRITE_ONCE(desc->buf1, cpu_to_le32(buf1));
> +					break;
> +				}
> +			}
> +
> +			spin_unlock_bh(&dev->rx_token_lock);
> +			if (!find)
> +				return NULL;
> +		}
>   
> +		t = mt76_rx_token_release(dev, token);
>   		if (!t)
>   			return NULL;
>   


[-- 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] 6+ messages in thread

* Re: [PATCH v1] mt76: mt7915: wed: find rx token by physical address
       [not found]   ` <e144d2ffe9924d81a7b60f38cdcf516a@realtek.com>
@ 2025-03-12  9:09     ` Felix Fietkau
  2025-03-13 12:43       ` Shengyu Qu
  0 siblings, 1 reply; 6+ messages in thread
From: Felix Fietkau @ 2025-03-12  9:09 UTC (permalink / raw)
  To: Ping-Ke Shih, Shengyu Qu, lorenzo@kernel.org,
	ryder.lee@mediatek.com, shayne.chen@mediatek.com,
	sean.wang@mediatek.com, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
  Cc: johannes@sipsolutions.net, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, Peter Chiu

On 12.03.25 02:41, Ping-Ke Shih wrote:
> Shengyu Qu <wiagn233@outlook.com> wrote:
>> 
>> Hi Shih,
>> 
>> Can you also give this patch a review? Seems I also need to convert to
>> reverse Xmas tree order for this patch, will do it in next version.
> 
> Yes. Please do it.
> 
>> 
>> Best regards,
>> Shengyu
>> 
>> 在 2025/2/22 19:38, Shengyu Qu 写道:
>> > The token id in RxDMAD may be incorrect when it is not the last frame
>> > due to WED HW bug. Lookup correct token id by physical address in sdp0.
>> >
>> > Downstream patch link:
>> https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/737340322ab22b138fd200e02
>> 0d61ffdbe3e36a9/autobuild/autobuild_5.4_mac80211_release/mt7988_wifi7_mac80211_mlo/package/kernel/mt76
>> /patches/0062-mtk-wifi-mt76-mt7915-wed-find-rx-token-by-physical-a.patch
>> >
>> > Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
>> > Signed-off-by: Shengyu Qu <wiagn233@outlook.com>
>> > ---
>> >   drivers/net/wireless/mediatek/mt76/dma.c | 25 +++++++++++++++++++++++-
>> >   1 file changed, 24 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
>> > index 844af16ee551..5bf63014263c 100644
>> > --- a/drivers/net/wireless/mediatek/mt76/dma.c
>> > +++ b/drivers/net/wireless/mediatek/mt76/dma.c
>> > @@ -444,9 +444,32 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
>> >   	mt76_dma_should_drop_buf(drop, ctrl, buf1, desc_info);
>> >
>> >   	if (mt76_queue_is_wed_rx(q)) {
>> > +		u32 id, find = 0;
>> >   		u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1);
>> > -		struct mt76_txwi_cache *t = mt76_rx_token_release(dev, token);
>> > +		struct mt76_txwi_cache *t;
>> > +
>> > +		if (*more) {
> 
> Because of scope, should define 'find' (or 'found'?) as bool here.
> 
>> > +			spin_lock_bh(&dev->rx_token_lock);
>> > +
>> > +			idr_for_each_entry(&dev->rx_token, t, id) {
> 
> idr_find() can only get a pointer associated with the ID. Not sure if it can
> have a reverse way -- get ID from pointer. With sequential search in data path,
> cost is higher.
> 
> Maybe you can consider to build association between argument 'idx' and
> pointer/token by another patch.
> 
> But logic is okay to me.

Adding to that, it matters how frequently the token ID is incorrect. If 
the token ID is correct most of the time, then it's worth optimizing for 
that as the default case. In that case you should avoid the extra idr 
scan if the pointer for the provided token id already matches.

- Felix


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] mt76: mt7915: wed: find rx token by physical address
  2025-03-12  9:09     ` Felix Fietkau
@ 2025-03-13 12:43       ` Shengyu Qu
  2025-03-13 12:47         ` Felix Fietkau
  0 siblings, 1 reply; 6+ messages in thread
From: Shengyu Qu @ 2025-03-13 12:43 UTC (permalink / raw)
  To: Felix Fietkau, Ping-Ke Shih, lorenzo@kernel.org,
	ryder.lee@mediatek.com, shayne.chen@mediatek.com,
	sean.wang@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, johannes@sipsolutions.net, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, Peter Chiu


[-- Attachment #1.1.1: Type: text/plain, Size: 3057 bytes --]

Hi Felix,

I'm not sure about the token ID incorrect frequency, this is just a port
of downstream patch, sorry.

Best regards,
Shengyu

在 2025/3/12 17:09, Felix Fietkau 写道:
> On 12.03.25 02:41, Ping-Ke Shih wrote:
>> Shengyu Qu <wiagn233@outlook.com> wrote:
>>>
>>> Hi Shih,
>>>
>>> Can you also give this patch a review? Seems I also need to convert to
>>> reverse Xmas tree order for this patch, will do it in next version.
>>
>> Yes. Please do it.
>>
>>>
>>> Best regards,
>>> Shengyu
>>>
>>> 在 2025/2/22 19:38, Shengyu Qu 写道:
>>> > The token id in RxDMAD may be incorrect when it is not the last frame
>>> > due to WED HW bug. Lookup correct token id by physical address in 
>>> sdp0.
>>> >
>>> > Downstream patch link:
>>> https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt- 
>>> feeds/+/737340322ab22b138fd200e02
>>> 0d61ffdbe3e36a9/autobuild/autobuild_5.4_mac80211_release/ 
>>> mt7988_wifi7_mac80211_mlo/package/kernel/mt76
>>> /patches/0062-mtk-wifi-mt76-mt7915-wed-find-rx-token-by-physical-a.patch
>>> >
>>> > Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
>>> > Signed-off-by: Shengyu Qu <wiagn233@outlook.com>
>>> > ---
>>> >   drivers/net/wireless/mediatek/mt76/dma.c | 25 +++++++++++++++++++ 
>>> ++++-
>>> >   1 file changed, 24 insertions(+), 1 deletion(-)
>>> >
>>> > diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/ 
>>> net/wireless/mediatek/mt76/dma.c
>>> > index 844af16ee551..5bf63014263c 100644
>>> > --- a/drivers/net/wireless/mediatek/mt76/dma.c
>>> > +++ b/drivers/net/wireless/mediatek/mt76/dma.c
>>> > @@ -444,9 +444,32 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct 
>>> mt76_queue *q, int idx,
>>> >       mt76_dma_should_drop_buf(drop, ctrl, buf1, desc_info);
>>> >
>>> >       if (mt76_queue_is_wed_rx(q)) {
>>> > +        u32 id, find = 0;
>>> >           u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1);
>>> > -        struct mt76_txwi_cache *t = mt76_rx_token_release(dev, 
>>> token);
>>> > +        struct mt76_txwi_cache *t;
>>> > +
>>> > +        if (*more) {
>>
>> Because of scope, should define 'find' (or 'found'?) as bool here.
>>
>>> > +            spin_lock_bh(&dev->rx_token_lock);
>>> > +
>>> > +            idr_for_each_entry(&dev->rx_token, t, id) {
>>
>> idr_find() can only get a pointer associated with the ID. Not sure if 
>> it can
>> have a reverse way -- get ID from pointer. With sequential search in 
>> data path,
>> cost is higher.
>>
>> Maybe you can consider to build association between argument 'idx' and
>> pointer/token by another patch.
>>
>> But logic is okay to me.
> 
> Adding to that, it matters how frequently the token ID is incorrect. If 
> the token ID is correct most of the time, then it's worth optimizing for 
> that as the default case. In that case you should avoid the extra idr 
> scan if the pointer for the provided token id already matches.
> 
> - Felix


[-- 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] 6+ messages in thread

* Re: [PATCH v1] mt76: mt7915: wed: find rx token by physical address
  2025-03-13 12:43       ` Shengyu Qu
@ 2025-03-13 12:47         ` Felix Fietkau
  2025-03-13 13:09           ` Shengyu Qu
  0 siblings, 1 reply; 6+ messages in thread
From: Felix Fietkau @ 2025-03-13 12:47 UTC (permalink / raw)
  To: Shengyu Qu, Ping-Ke Shih, lorenzo@kernel.org,
	ryder.lee@mediatek.com, shayne.chen@mediatek.com,
	sean.wang@mediatek.com, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
  Cc: johannes@sipsolutions.net, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, Peter Chiu

On 13.03.25 13:43, Shengyu Qu wrote:
> Hi Felix,
> 
> I'm not sure about the token ID incorrect frequency, this is just a port
> of downstream patch, sorry.

Can you reproduce the issue that the downstream patch supposedly fixes?
If so, you could add some printk to check how frequently it occurs.

- Felix


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] mt76: mt7915: wed: find rx token by physical address
  2025-03-13 12:47         ` Felix Fietkau
@ 2025-03-13 13:09           ` Shengyu Qu
  0 siblings, 0 replies; 6+ messages in thread
From: Shengyu Qu @ 2025-03-13 13:09 UTC (permalink / raw)
  To: Felix Fietkau, Ping-Ke Shih, lorenzo@kernel.org,
	ryder.lee@mediatek.com, shayne.chen@mediatek.com,
	sean.wang@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, johannes@sipsolutions.net, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, Peter Chiu


[-- Attachment #1.1.1: Type: text/plain, Size: 548 bytes --]

Can you do the test? I'll be busy for months since tomorrow, so really 
don't have time to do this test...

I'll send the patch v2 first.

Best regards,
Shengyu

在 2025/3/13 20:47, Felix Fietkau 写道:
> On 13.03.25 13:43, Shengyu Qu wrote:
>> Hi Felix,
>>
>> I'm not sure about the token ID incorrect frequency, this is just a port
>> of downstream patch, sorry.
> 
> Can you reproduce the issue that the downstream patch supposedly fixes?
> If so, you could add some printk to check how frequently it occurs.
> 
> - Felix


[-- 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] 6+ messages in thread

end of thread, other threads:[~2025-03-13 13:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-22 11:38 [PATCH v1] mt76: mt7915: wed: find rx token by physical address Shengyu Qu
2025-03-11  8:51 ` Shengyu Qu
     [not found]   ` <e144d2ffe9924d81a7b60f38cdcf516a@realtek.com>
2025-03-12  9:09     ` Felix Fietkau
2025-03-13 12:43       ` Shengyu Qu
2025-03-13 12:47         ` Felix Fietkau
2025-03-13 13:09           ` Shengyu Qu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).