Skip to contentSkip to conversation

mt76: mt76u_vendor_request: Do not print error messages when -EPROTO

PATCH In review WangYuli 4 participants 7 messages Dec 18, 2024 – Dec 24, 2024

Subsystems (5)
lore
Share & tools
lore

WangYuli

author
#0 lore raw

PATCH 1/1 mt76: mt76u_vendor_request: Do not print error messages when -EPROTO

When initializing the network card, unplugging the device will trigger an -EPROTO error, resulting in a flood of error messages being printed frantically.

---
 drivers/net/wireless/mediatek/mt76/usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +2 -2
index 58ff06823389..f9e67b8c3b3c 100644
@@ -33,9 +33,9 @@ int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type,
 
 		ret = usb_control_msg(udev, pipe, req, req_type, val,
 				      offset, buf, len, MT_VEND_REQ_TOUT_MS);
-		if (ret == -ENODEV)
+		if (ret == -ENODEV || ret == -EPROTO)
 			set_bit(MT76_REMOVED, &dev->phy.state);
-		if (ret >= 0 || ret == -ENODEV)
+		if (ret >= 0 || ret == -ENODEV || ret == -EPROTO)
 			return ret;
 		usleep_range(5000, 10000);
 	}
Signature · 1 line
2.45.2
#1 lore raw

From: Wangyuli <[email protected]>
Date: Wed, 18 Dec 2024 17:08:33 +0800

Quoted 1 line

[RESEND. PATCH] mt76: mt76u_vendor_request: Do not print error messages when -EPROTO

Is it a fix or an improvement?
You need to specify the target tree, either 'PATCH net' (fixes) or 'PATCH net-next' (improvements).

The '.' after 'RESEND' is not needed.

Quoted 4 lines

When initializing the network card, unplugging the device will trigger an -EPROTO error, resulting in a flood of error messages being printed frantically.

If it's a fix, you need to have a 'Fixes:' tag here.

Quoted 12 lines
---
 drivers/net/wireless/mediatek/mt76/usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +0 -0
index 58ff06823389..f9e67b8c3b3c 100644

drivers/net/wireless/mediatek/mt76/usb.c int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type, · line 40

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/usb.c +2 -2
@@ -33,9 +33,9 @@ int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type,
 
 		ret = usb_control_msg(udev, pipe, req, req_type, val,
 				      offset, buf, len, MT_VEND_REQ_TOUT_MS);
-		if (ret == -ENODEV)
+		if (ret == -ENODEV || ret == -EPROTO)
 			set_bit(MT76_REMOVED, &dev->phy.state);
-		if (ret >= 0 || ret == -ENODEV)
+		if (ret >= 0 || ret == -ENODEV || ret == -EPROTO)
 			return ret;
 		usleep_range(5000, 10000);

How do other drivers handle this?
Can -EPROTO happen in other cases, not only unplugging, which this patch would break?

Thanks,
Olek

#2 lore raw
Quoted 8 lines · Alexander Lobakin

From: Wangyuli <[email protected]>
Date: Wed, 18 Dec 2024 17:08:33 +0800

Quoted 1 line

[RESEND. PATCH] mt76: mt76u_vendor_request: Do not print error messages when -EPROTO

Is it a fix or an improvement?
You need to specify the target tree, either 'PATCH net' (fixes) or 'PATCH net-next' (improvements).

Actually this is a wireless driver so the options are either wireless tree or Felix' tree (for -next). And please add 'wifi:' to subject.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
author
#3 lore raw
In reply to Alexander Lobakin
Quoted 3 lines · Alexander Lobakin

Is it a fix or an improvement?
You need to specify the target tree, either 'PATCH net' (fixes) or 'PATCH net-next' (improvements).

 It is a fix not an improvement.

Quoted 4 lines

How do other drivers handle this?
Can -EPROTO happen in other cases, not only unplugging, which this patch would break?

When initializing the network card, unplugging the device will trigger an -EPROTO error.

The exception is printed as follows:

        mt76x2u 2-2.4:1.0: vendor request req:47 off:9018 failed:-71 mt76x2u 2-2.4:1.0: vendor request req:47 off:9018 failed:-71
        ...

It will continue to print more than 2000 times for about 5 minutes, causing the usb device to be unable to be disconnected. During this period, the usb port cannot recognize the new device because the old device has not disconnected.

There may be other operating methods that cause -EPROTO, but -EPROTO is a low-level hardware error. It is unwise to repeat vendor requests expecting to read correct data. It is a better choice to treat -EPROTO and -ENODEV the same way。

Similar to commit (mt76: usb: process URBs with status EPROTO properly)do no schedule rx_worker for urb marked with status set -EPROTO. I also reproduced this situation when plugging and unplugging the device, and this patch is effective.

Just do not vendor request again for urb marked with status set -EPROTO .

Thanks,

Signature · 1 line
WangYuli
#4 lore raw

From: Wangyuli <[email protected]>
Date: Thu, 19 Dec 2024 15:11:24 +0800

Quoted 6 lines · Alexander Lobakin
Quoted 4 lines

Is it a fix or an improvement?
You need to specify the target tree, either 'PATCH net' (fixes) or 'PATCH net-next' (improvements).

 It is a fix not an improvement.

So you need to add the correct tree and/or subject prefix and specify "Fixes:" tag with the commit this change fixes.

Quoted 25 lines
Quoted 4 lines

How do other drivers handle this?
Can -EPROTO happen in other cases, not only unplugging, which this patch would break?

When initializing the network card, unplugging the device will trigger an -EPROTO error.

The exception is printed as follows:


        mt76x2u 2-2.4:1.0: vendor request req:47 off:9018 failed:-71 mt76x2u 2-2.4:1.0: vendor request req:47 off:9018 failed:-71
        ...

It will continue to print more than 2000 times for about 5 minutes, causing the usb device to be unable to be disconnected.  During this period, the usb port cannot recognize the new device because the old device has not disconnected.

There may be other operating methods that cause -EPROTO, but -EPROTO is a low-level hardware error. It is unwise to repeat vendor requests expecting to read correct data. It is a better choice to treat -EPROTO and -ENODEV the same way.

Quoted 4 lines

Similar to commit (mt76: usb: process URBs with status EPROTO properly)do no schedule rx_worker for urb marked with status set - EPROTO. I also reproduced this situation when plugging and unplugging the device, and this patch is effective.

I'm not a wireless expert, from my PoV sounds good. Just describe everything in details in the commit message, so that it will be clear for everyone.

Quoted 8 lines

Just do not vendor request again for urb marked with status set -EPROTO .

Thanks,

Signature · 1 line
WangYuli

Thanks,
Olek

author
#5 lore raw
Quoted 7 lines · Alexander Lobakin

So you need to add the correct tree and/or subject prefix and specify "Fixes:" tag with the commit this change fixes.

Quoted 1 line

...

I'm not a wireless expert, from my PoV sounds good. Just describe everything in details in the commit message, so that it will be clear for everyone.

Hi, I have attached the new patch as requested for your review.

Please let me know if you have any questions.

Thanks,

Signature · 1 line
WangYuli
#6 lore raw

Re: mt76: dealing with disconnections, -ENODEV and -EPROTO

In reply to Alexander Lobakin
Quoted 5 lines
Quoted 5 lines
drivers/net/wireless/mediatek/mt76/usb.c +1 -1
 		ret = usb_control_msg(udev, pipe, req, req_type, val,
 				      offset, buf, len, MT_VEND_REQ_TOUT_MS);
-		if (ret == -ENODEV)
+		if (ret == -ENODEV || ret == -EPROTO)
 			set_bit(MT76_REMOVED, &dev->phy.state);
Quoted 8 lines

drivers/net/wireless/mediatek/mt76/usb.c int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type, · line 40

Quoted 4 lines
drivers/net/wireless/mediatek/mt76/usb.c +1 -1
-		if (ret >= 0 || ret == -ENODEV)
+		if (ret >= 0 || ret == -ENODEV || ret == -EPROTO)
 			return ret;
 		usleep_range(5000, 10000);

How do other drivers handle this?
Can -EPROTO happen in other cases, not only unplugging, which this patch would break?

Yes, -EPROTO may be a transient error, although they are relatively rare as some retries are done before the URB fails. This patch will only break things if things work in the first place, i.e. the driver has sensible retry policies, the hardware doesn't get confused, etc.

Note that -EPROTO is not guaranteed in this case, see Documentation/driver-api/usb/error-codes.rst

I know that xHCI gives -EPROTO and it looks like EHCI does too (IDK if this is reliable), but I just checked that OHCI gives -ETIME.

I don't have this hardware, but I played with some other wired/WiFi dongles and observed similar problems of varying severity.

It looks to me like USB core doesn't actually return -ENODEV on disconnected devices, or at least doesn't react to disconnection until .probe() returns, I am not yet sure which of those.

And drivers don't seem to expect -EPROTO or -ETIME to be fatal.

And maybe they should, if they wouldn't be able to recover from it anyway, and I know that there are drivers which can't. But I think this USB subsystem behavior is suboptimal too.

Regards,
Michal