1 From 0381bfbc400ce4c3000b0b31c577ad9e8071e4f6 Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Fri, 18 May 2018 12:25:08 +0200
4 Subject: [PATCH 1/5] rt2800: move usb specific txdone/txstatus routines to
7 In order to reuse usb txdone/txstatus routines for mmio, move them
8 to common rt2800lib.c file.
10 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
12 .../net/wireless/ralink/rt2x00/rt2800lib.c | 138 +++++++++++++++++
13 .../net/wireless/ralink/rt2x00/rt2800lib.h | 3 +
14 .../net/wireless/ralink/rt2x00/rt2800usb.c | 143 +-----------------
15 3 files changed, 145 insertions(+), 139 deletions(-)
17 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
18 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
19 @@ -960,6 +960,47 @@ static void rt2800_rate_from_status(stru
20 skbdesc->tx_rate_flags = flags;
23 +static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg)
28 + int tx_wcid, tx_ack, tx_pid, is_agg;
31 + * This frames has returned with an IO error,
32 + * so the status report is not intended for this
35 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
38 + wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
39 + ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
40 + pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
41 + is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
44 + * Validate if this TX status report is intended for
45 + * this entry by comparing the WCID/ACK/PID fields.
47 + txwi = rt2800_drv_get_txwi(entry);
49 + word = rt2x00_desc_read(txwi, 1);
50 + tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
51 + tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
52 + tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
54 + if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
55 + rt2x00_dbg(entry->queue->rt2x00dev,
56 + "TX status report missed for queue %d entry %d\n",
57 + entry->queue->qid, entry->entry_idx);
64 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
67 @@ -1062,6 +1103,103 @@ void rt2800_txdone_entry(struct queue_en
69 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
71 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev)
73 + struct data_queue *queue;
74 + struct queue_entry *entry;
79 + while (kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
81 + * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
82 + * guaranteed to be one of the TX QIDs .
84 + qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
85 + queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
87 + if (unlikely(rt2x00queue_empty(queue))) {
88 + rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
93 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
95 + if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
96 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
97 + rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
98 + entry->entry_idx, qid);
102 + match = rt2800_txdone_entry_check(entry, reg);
103 + rt2800_txdone_entry(entry, reg, rt2800_drv_get_txwi(entry), match);
106 +EXPORT_SYMBOL_GPL(rt2800_txdone);
108 +static inline bool rt2800_entry_txstatus_timeout(struct queue_entry *entry)
112 + if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
115 + tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
116 + if (unlikely(tout))
117 + rt2x00_dbg(entry->queue->rt2x00dev,
118 + "TX status timeout for entry %d in queue %d\n",
119 + entry->entry_idx, entry->queue->qid);
124 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
126 + struct data_queue *queue;
127 + struct queue_entry *entry;
129 + tx_queue_for_each(rt2x00dev, queue) {
130 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
131 + if (rt2800_entry_txstatus_timeout(entry))
136 +EXPORT_SYMBOL_GPL(rt2800_txstatus_timeout);
138 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
140 + struct data_queue *queue;
141 + struct queue_entry *entry;
144 + * Process any trailing TX status reports for IO failures,
145 + * we loop until we find the first non-IO error entry. This
146 + * can either be a frame which is free, is being uploaded,
147 + * or has completed the upload but didn't have an entry
148 + * in the TX_STAT_FIFO register yet.
150 + tx_queue_for_each(rt2x00dev, queue) {
151 + while (!rt2x00queue_empty(queue)) {
152 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
154 + if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
155 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
158 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
159 + rt2800_entry_txstatus_timeout(entry))
160 + rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
166 +EXPORT_SYMBOL_GPL(rt2800_txdone_nostatus);
168 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
171 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
172 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
173 @@ -206,6 +206,9 @@ void rt2800_process_rxwi(struct queue_en
175 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
177 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev);
178 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
179 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
181 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
182 void rt2800_clear_beacon(struct queue_entry *entry);
183 --- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
184 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
185 @@ -116,35 +116,6 @@ static bool rt2800usb_txstatus_pending(s
189 -static inline bool rt2800usb_entry_txstatus_timeout(struct queue_entry *entry)
193 - if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
196 - tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
197 - if (unlikely(tout))
198 - rt2x00_dbg(entry->queue->rt2x00dev,
199 - "TX status timeout for entry %d in queue %d\n",
200 - entry->entry_idx, entry->queue->qid);
205 -static bool rt2800usb_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
207 - struct data_queue *queue;
208 - struct queue_entry *entry;
210 - tx_queue_for_each(rt2x00dev, queue) {
211 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
212 - if (rt2800usb_entry_txstatus_timeout(entry))
218 #define TXSTATUS_READ_INTERVAL 1000000
220 static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
221 @@ -171,7 +142,7 @@ static bool rt2800usb_tx_sta_fifo_read_c
224 /* Check if there is any entry that timedout waiting on TX status */
225 - if (rt2800usb_txstatus_timeout(rt2x00dev))
226 + if (rt2800_txstatus_timeout(rt2x00dev))
227 queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
229 if (rt2800usb_txstatus_pending(rt2x00dev)) {
230 @@ -501,123 +472,17 @@ static int rt2800usb_get_tx_data_len(str
232 * TX control handlers
234 -static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
238 - int wcid, ack, pid;
239 - int tx_wcid, tx_ack, tx_pid, is_agg;
242 - * This frames has returned with an IO error,
243 - * so the status report is not intended for this
246 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
249 - wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
250 - ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
251 - pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
252 - is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
255 - * Validate if this TX status report is intended for
256 - * this entry by comparing the WCID/ACK/PID fields.
258 - txwi = rt2800usb_get_txwi(entry);
260 - word = rt2x00_desc_read(txwi, 1);
261 - tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
262 - tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
263 - tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
265 - if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
266 - rt2x00_dbg(entry->queue->rt2x00dev,
267 - "TX status report missed for queue %d entry %d\n",
268 - entry->queue->qid, entry->entry_idx);
275 -static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
277 - struct data_queue *queue;
278 - struct queue_entry *entry;
283 - while (kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
285 - * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
286 - * guaranteed to be one of the TX QIDs .
288 - qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
289 - queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
291 - if (unlikely(rt2x00queue_empty(queue))) {
292 - rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
297 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
299 - if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
300 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
301 - rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
302 - entry->entry_idx, qid);
306 - match = rt2800usb_txdone_entry_check(entry, reg);
307 - rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
311 -static void rt2800usb_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
313 - struct data_queue *queue;
314 - struct queue_entry *entry;
317 - * Process any trailing TX status reports for IO failures,
318 - * we loop until we find the first non-IO error entry. This
319 - * can either be a frame which is free, is being uploaded,
320 - * or has completed the upload but didn't have an entry
321 - * in the TX_STAT_FIFO register yet.
323 - tx_queue_for_each(rt2x00dev, queue) {
324 - while (!rt2x00queue_empty(queue)) {
325 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
327 - if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
328 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
331 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
332 - rt2800usb_entry_txstatus_timeout(entry))
333 - rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
340 static void rt2800usb_work_txdone(struct work_struct *work)
342 struct rt2x00_dev *rt2x00dev =
343 container_of(work, struct rt2x00_dev, txdone_work);
345 while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
346 - rt2800usb_txstatus_timeout(rt2x00dev)) {
347 + rt2800_txstatus_timeout(rt2x00dev)) {
349 - rt2800usb_txdone(rt2x00dev);
350 + rt2800_txdone(rt2x00dev);
352 - rt2800usb_txdone_nostatus(rt2x00dev);
353 + rt2800_txdone_nostatus(rt2x00dev);
356 * The hw may delay sending the packet after DMA complete