hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
....@@ -1,20 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
34 Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
45 <http://rt2x00.serialmonkey.com>
56
6
- This program is free software; you can redistribute it and/or modify
7
- it under the terms of the GNU General Public License as published by
8
- the Free Software Foundation; either version 2 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- You should have received a copy of the GNU General Public License
17
- along with this program; if not, see <http://www.gnu.org/licenses/>.
187 */
198
209 /*
....@@ -30,6 +19,25 @@
3019
3120 #include "rt2x00.h"
3221 #include "rt2x00usb.h"
22
+
23
+static bool rt2x00usb_check_usb_error(struct rt2x00_dev *rt2x00dev, int status)
24
+{
25
+ if (status == -ENODEV || status == -ENOENT)
26
+ return true;
27
+
28
+ if (!test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
29
+ return false;
30
+
31
+ if (status == -EPROTO || status == -ETIMEDOUT)
32
+ rt2x00dev->num_proto_errs++;
33
+ else
34
+ rt2x00dev->num_proto_errs = 0;
35
+
36
+ if (rt2x00dev->num_proto_errs > 3)
37
+ return true;
38
+
39
+ return false;
40
+}
3341
3442 /*
3543 * Interfacing with the HW.
....@@ -57,7 +65,7 @@
5765 if (status >= 0)
5866 return 0;
5967
60
- if (status == -ENODEV || status == -ENOENT) {
68
+ if (rt2x00usb_check_usb_error(rt2x00dev, status)) {
6169 /* Device has disappeared. */
6270 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
6371 break;
....@@ -321,7 +329,7 @@
321329
322330 status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
323331 if (status) {
324
- if (status == -ENODEV || status == -ENOENT)
332
+ if (rt2x00usb_check_usb_error(rt2x00dev, status))
325333 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
326334 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
327335 rt2x00lib_dmadone(entry);
....@@ -344,8 +352,7 @@
344352 while (!rt2x00queue_empty(rt2x00dev->rx)) {
345353 entry = rt2x00queue_get_entry(rt2x00dev->rx, Q_INDEX_DONE);
346354
347
- if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
348
- !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
355
+ if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
349356 break;
350357
351358 /*
....@@ -367,13 +374,8 @@
367374 struct queue_entry *entry = (struct queue_entry *)urb->context;
368375 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
369376
370
- if (!test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
377
+ if (!test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
371378 return;
372
-
373
- /*
374
- * Report the frame as DMA done
375
- */
376
- rt2x00lib_dmadone(entry);
377379
378380 /*
379381 * Check if the received data is simply too small
....@@ -384,8 +386,12 @@
384386 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
385387
386388 /*
387
- * Schedule the delayed work for reading the RX status
388
- * from the device.
389
+ * Report the frame as DMA done
390
+ */
391
+ rt2x00lib_dmadone(entry);
392
+
393
+ /*
394
+ * Schedule the delayed work for processing RX data
389395 */
390396 queue_work(rt2x00dev->workqueue, &rt2x00dev->rxdone_work);
391397 }
....@@ -397,8 +403,7 @@
397403 struct queue_entry_priv_usb *entry_priv = entry->priv_data;
398404 int status;
399405
400
- if (test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
401
- test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
406
+ if (test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
402407 return false;
403408
404409 rt2x00lib_dmastart(entry);
....@@ -410,7 +415,7 @@
410415
411416 status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
412417 if (status) {
413
- if (status == -ENODEV || status == -ENOENT)
418
+ if (rt2x00usb_check_usb_error(rt2x00dev, status))
414419 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
415420 set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
416421 rt2x00lib_dmadone(entry);
....@@ -520,7 +525,7 @@
520525
521526 static void rt2x00usb_watchdog_tx_dma(struct data_queue *queue)
522527 {
523
- rt2x00_warn(queue->rt2x00dev, "TX queue %d DMA timed out, invoke forced forced reset\n",
528
+ rt2x00_warn(queue->rt2x00dev, "TX queue %d DMA timed out, invoke forced reset\n",
524529 queue->qid);
525530
526531 rt2x00queue_stop_queue(queue);
....@@ -884,7 +889,7 @@
884889 struct ieee80211_hw *hw = usb_get_intfdata(usb_intf);
885890 struct rt2x00_dev *rt2x00dev = hw->priv;
886891
887
- return rt2x00lib_suspend(rt2x00dev, state);
892
+ return rt2x00lib_suspend(rt2x00dev);
888893 }
889894 EXPORT_SYMBOL_GPL(rt2x00usb_suspend);
890895