ath79: modify device name of I-O DATA WN-AC1600DGR2
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / rt2x00 / 022-rt2x00-check-number-of-EPROTO-errors.patch
1 From patchwork Tue Mar 12 09:51:42 2019
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: Stanislaw Gruszka <sgruszka@redhat.com>
6 X-Patchwork-Id: 10848961
7 X-Patchwork-Delegate: kvalo@adurom.com
8 From: Stanislaw Gruszka <sgruszka@redhat.com>
9 To: linux-wireless@vger.kernel.org
10 Cc: =?utf-8?q?Tomislav_Po=C5=BEega?= <pozega.tomislav@gmail.com>,
11 Daniel Golle <daniel@makrotopia.org>, Felix Fietkau <nbd@nbd.name>,
12 Mathias Kresin <dev@kresin.me>
13 Subject: [PATCH v3 3/4] rt2x00: check number of EPROTO errors
14 Date: Tue, 12 Mar 2019 10:51:42 +0100
15 Message-Id: <1552384303-29529-4-git-send-email-sgruszka@redhat.com>
16 In-Reply-To: <1552384303-29529-1-git-send-email-sgruszka@redhat.com>
17 References: <1552384303-29529-1-git-send-email-sgruszka@redhat.com>
18
19 Some USB host devices/drivers on some conditions can always return
20 EPROTO error on submitted URBs. That can cause infinity loop in the
21 rt2x00 driver.
22
23 Since we can have single EPROTO errors we can not mark as device as
24 removed to avoid infinity loop. However we can count consecutive
25 EPROTO errors and mark device as removed if get lot of it.
26 I choose number 10 as threshold.
27
28 Reported-and-tested-by: Randy Oostdyk <linux-kernel@oostdyk.com>
29 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
30 ---
31 drivers/net/wireless/ralink/rt2x00/rt2x00.h | 1 +
32 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 22 +++++++++++++++++++---
33 2 files changed, 20 insertions(+), 3 deletions(-)
34
35 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
36 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
37 @@ -1017,6 +1017,7 @@ struct rt2x00_dev {
38 unsigned int extra_tx_headroom;
39
40 struct usb_anchor *anchor;
41 + unsigned int num_proto_errs;
42
43 /* Clock for System On Chip devices. */
44 struct clk *clk;
45 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
46 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
47 @@ -31,6 +31,22 @@
48 #include "rt2x00.h"
49 #include "rt2x00usb.h"
50
51 +static bool rt2x00usb_check_usb_error(struct rt2x00_dev *rt2x00dev, int status)
52 +{
53 + if (status == -ENODEV || status == -ENOENT)
54 + return true;
55 +
56 + if (status == -EPROTO || status == -ETIMEDOUT)
57 + rt2x00dev->num_proto_errs++;
58 + else
59 + rt2x00dev->num_proto_errs = 0;
60 +
61 + if (rt2x00dev->num_proto_errs > 3)
62 + return true;
63 +
64 + return false;
65 +}
66 +
67 /*
68 * Interfacing with the HW.
69 */
70 @@ -57,7 +73,7 @@ int rt2x00usb_vendor_request(struct rt2x
71 if (status >= 0)
72 return 0;
73
74 - if (status == -ENODEV || status == -ENOENT) {
75 + if (rt2x00usb_check_usb_error(rt2x00dev, status)) {
76 /* Device has disappeared. */
77 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
78 break;
79 @@ -321,7 +337,7 @@ static bool rt2x00usb_kick_tx_entry(stru
80
81 status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
82 if (status) {
83 - if (status == -ENODEV || status == -ENOENT)
84 + if (rt2x00usb_check_usb_error(rt2x00dev, status))
85 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
86 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
87 rt2x00lib_dmadone(entry);
88 @@ -410,7 +426,7 @@ static bool rt2x00usb_kick_rx_entry(stru
89
90 status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
91 if (status) {
92 - if (status == -ENODEV || status == -ENOENT)
93 + if (rt2x00usb_check_usb_error(rt2x00dev, status))
94 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
95 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
96 rt2x00lib_dmadone(entry);