hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
34 Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
....@@ -7,18 +8,6 @@
78 Copyright (C) 2009 Axel Kollhofer <rain_maker@root-forum.org>
89 <http://rt2x00.serialmonkey.com>
910
10
- This program is free software; you can redistribute it and/or modify
11
- it under the terms of the GNU General Public License as published by
12
- the Free Software Foundation; either version 2 of the License, or
13
- (at your option) any later version.
14
-
15
- This program is distributed in the hope that it will be useful,
16
- but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- GNU General Public License for more details.
19
-
20
- You should have received a copy of the GNU General Public License
21
- along with this program; if not, see <http://www.gnu.org/licenses/>.
2211 */
2312
2413 /*
....@@ -100,51 +89,6 @@
10089 }
10190 }
10291
103
-/*
104
- * test if there is an entry in any TX queue for which DMA is done
105
- * but the TX status has not been returned yet
106
- */
107
-static bool rt2800usb_txstatus_pending(struct rt2x00_dev *rt2x00dev)
108
-{
109
- struct data_queue *queue;
110
-
111
- tx_queue_for_each(rt2x00dev, queue) {
112
- if (rt2x00queue_get_entry(queue, Q_INDEX_DMA_DONE) !=
113
- rt2x00queue_get_entry(queue, Q_INDEX_DONE))
114
- return true;
115
- }
116
- return false;
117
-}
118
-
119
-static inline bool rt2800usb_entry_txstatus_timeout(struct queue_entry *entry)
120
-{
121
- bool tout;
122
-
123
- if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
124
- return false;
125
-
126
- tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
127
- if (unlikely(tout))
128
- rt2x00_dbg(entry->queue->rt2x00dev,
129
- "TX status timeout for entry %d in queue %d\n",
130
- entry->entry_idx, entry->queue->qid);
131
- return tout;
132
-
133
-}
134
-
135
-static bool rt2800usb_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
136
-{
137
- struct data_queue *queue;
138
- struct queue_entry *entry;
139
-
140
- tx_queue_for_each(rt2x00dev, queue) {
141
- entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
142
- if (rt2800usb_entry_txstatus_timeout(entry))
143
- return true;
144
- }
145
- return false;
146
-}
147
-
14892 #define TXSTATUS_READ_INTERVAL 1000000
14993
15094 static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
....@@ -171,10 +115,10 @@
171115 }
172116
173117 /* Check if there is any entry that timedout waiting on TX status */
174
- if (rt2800usb_txstatus_timeout(rt2x00dev))
118
+ if (rt2800_txstatus_timeout(rt2x00dev))
175119 queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
176120
177
- if (rt2800usb_txstatus_pending(rt2x00dev)) {
121
+ if (rt2800_txstatus_pending(rt2x00dev)) {
178122 /* Read register after 1 ms */
179123 hrtimer_start(&rt2x00dev->txstatus_timer,
180124 TXSTATUS_READ_INTERVAL,
....@@ -189,7 +133,7 @@
189133 * clear_bit someone could do rt2x00usb_interrupt_txdone, so recheck
190134 * here again if status reading is needed.
191135 */
192
- if (rt2800usb_txstatus_pending(rt2x00dev) &&
136
+ if (rt2800_txstatus_pending(rt2x00dev) &&
193137 !test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
194138 return true;
195139 else
....@@ -435,6 +379,14 @@
435379 return retval;
436380 }
437381
382
+static unsigned int rt2800usb_get_dma_done(struct data_queue *queue)
383
+{
384
+ struct queue_entry *entry;
385
+
386
+ entry = rt2x00queue_get_entry(queue, Q_INDEX_DMA_DONE);
387
+ return entry->entry_idx;
388
+}
389
+
438390 /*
439391 * TX descriptor initialization
440392 */
....@@ -501,130 +453,24 @@
501453 /*
502454 * TX control handlers
503455 */
504
-static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
505
-{
506
- __le32 *txwi;
507
- u32 word;
508
- int wcid, ack, pid;
509
- int tx_wcid, tx_ack, tx_pid, is_agg;
510
-
511
- /*
512
- * This frames has returned with an IO error,
513
- * so the status report is not intended for this
514
- * frame.
515
- */
516
- if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
517
- return false;
518
-
519
- wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
520
- ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
521
- pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
522
- is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
523
-
524
- /*
525
- * Validate if this TX status report is intended for
526
- * this entry by comparing the WCID/ACK/PID fields.
527
- */
528
- txwi = rt2800usb_get_txwi(entry);
529
-
530
- word = rt2x00_desc_read(txwi, 1);
531
- tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
532
- tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
533
- tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
534
-
535
- if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
536
- rt2x00_dbg(entry->queue->rt2x00dev,
537
- "TX status report missed for queue %d entry %d\n",
538
- entry->queue->qid, entry->entry_idx);
539
- return false;
540
- }
541
-
542
- return true;
543
-}
544
-
545
-static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
546
-{
547
- struct data_queue *queue;
548
- struct queue_entry *entry;
549
- u32 reg;
550
- u8 qid;
551
- bool match;
552
-
553
- while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
554
- /*
555
- * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
556
- * guaranteed to be one of the TX QIDs .
557
- */
558
- qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
559
- queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
560
-
561
- if (unlikely(rt2x00queue_empty(queue))) {
562
- rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
563
- qid);
564
- break;
565
- }
566
-
567
- entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
568
-
569
- if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
570
- !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
571
- rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
572
- entry->entry_idx, qid);
573
- break;
574
- }
575
-
576
- match = rt2800usb_txdone_entry_check(entry, reg);
577
- rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
578
- }
579
-}
580
-
581
-static void rt2800usb_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
582
-{
583
- struct data_queue *queue;
584
- struct queue_entry *entry;
585
-
586
- /*
587
- * Process any trailing TX status reports for IO failures,
588
- * we loop until we find the first non-IO error entry. This
589
- * can either be a frame which is free, is being uploaded,
590
- * or has completed the upload but didn't have an entry
591
- * in the TX_STAT_FIFO register yet.
592
- */
593
- tx_queue_for_each(rt2x00dev, queue) {
594
- while (!rt2x00queue_empty(queue)) {
595
- entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
596
-
597
- if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
598
- !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
599
- break;
600
-
601
- if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
602
- rt2800usb_entry_txstatus_timeout(entry))
603
- rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
604
- else
605
- break;
606
- }
607
- }
608
-}
609
-
610456 static void rt2800usb_work_txdone(struct work_struct *work)
611457 {
612458 struct rt2x00_dev *rt2x00dev =
613459 container_of(work, struct rt2x00_dev, txdone_work);
614460
615461 while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
616
- rt2800usb_txstatus_timeout(rt2x00dev)) {
462
+ rt2800_txstatus_timeout(rt2x00dev)) {
617463
618
- rt2800usb_txdone(rt2x00dev);
464
+ rt2800_txdone(rt2x00dev, UINT_MAX);
619465
620
- rt2800usb_txdone_nostatus(rt2x00dev);
466
+ rt2800_txdone_nostatus(rt2x00dev);
621467
622468 /*
623469 * The hw may delay sending the packet after DMA complete
624470 * if the medium is busy, thus the TX_STA_FIFO entry is
625471 * also delayed -> use a timer to retrieve it.
626472 */
627
- if (rt2800usb_txstatus_pending(rt2x00dev))
473
+ if (rt2800_txstatus_pending(rt2x00dev))
628474 rt2800usb_async_read_tx_status(rt2x00dev);
629475 }
630476 }
....@@ -697,13 +543,13 @@
697543 * stripped it from the frame. Signal this to mac80211.
698544 */
699545 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
700
-
546
+
701547 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) {
702548 rxdesc->flags |= RX_FLAG_DECRYPTED;
703549 } else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) {
704550 /*
705551 * In order to check the Michael Mic, the packet must have
706
- * been decrypted. Mac80211 doesnt check the MMIC failure
552
+ * been decrypted. Mac80211 doesnt check the MMIC failure
707553 * flag to initiate MMIC countermeasures if the decoded flag
708554 * has not been set.
709555 */
....@@ -808,6 +654,7 @@
808654 .get_survey = rt2800_get_survey,
809655 .get_ringparam = rt2x00mac_get_ringparam,
810656 .tx_frames_pending = rt2x00mac_tx_frames_pending,
657
+ .reconfig_complete = rt2x00mac_reconfig_complete,
811658 };
812659
813660 static const struct rt2800_ops rt2800usb_rt2800_ops = {
....@@ -823,6 +670,7 @@
823670 .drv_write_firmware = rt2800usb_write_firmware,
824671 .drv_init_registers = rt2800usb_init_registers,
825672 .drv_get_txwi = rt2800usb_get_txwi,
673
+ .drv_get_dma_done = rt2800usb_get_dma_done,
826674 };
827675
828676 static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
....@@ -840,6 +688,7 @@
840688 .link_tuner = rt2800_link_tuner,
841689 .gain_calibration = rt2800_gain_calibration,
842690 .vco_calibration = rt2800_vco_calibration,
691
+ .watchdog = rt2800_watchdog,
843692 .start_queue = rt2800usb_start_queue,
844693 .kick_queue = rt2x00usb_kick_queue,
845694 .stop_queue = rt2800usb_stop_queue,
....@@ -858,6 +707,7 @@
858707 .config_erp = rt2800_config_erp,
859708 .config_ant = rt2800_config_ant,
860709 .config = rt2800_config,
710
+ .pre_reset_hw = rt2800_pre_reset_hw,
861711 };
862712
863713 static void rt2800usb_queue_init(struct data_queue *queue)
....@@ -896,7 +746,6 @@
896746 break;
897747
898748 case QID_ATIM:
899
- /* fallthrough */
900749 default:
901750 BUG();
902751 break;
....@@ -1237,6 +1086,7 @@
12371086 { USB_DEVICE(0x0846, 0x9013) },
12381087 { USB_DEVICE(0x0846, 0x9019) },
12391088 /* Planex */
1089
+ { USB_DEVICE(0x2019, 0xed14) },
12401090 { USB_DEVICE(0x2019, 0xed19) },
12411091 /* Ralink */
12421092 { USB_DEVICE(0x148f, 0x3573) },