1 From 5c656c71b1bf5611ce8262bab338104e04d10b8d Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Wed, 26 Sep 2018 12:24:53 +0200
4 Subject: [PATCH 02/28] 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>
11 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
13 .../net/wireless/ralink/rt2x00/rt2800lib.c | 138 +++++++++++++++++
14 .../net/wireless/ralink/rt2x00/rt2800lib.h | 3 +
15 .../net/wireless/ralink/rt2x00/rt2800usb.c | 143 +-----------------
16 3 files changed, 145 insertions(+), 139 deletions(-)
18 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
19 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
20 @@ -957,6 +957,47 @@ static void rt2800_rate_from_status(stru
21 skbdesc->tx_rate_flags = flags;
24 +static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg)
29 + int tx_wcid, tx_ack, tx_pid, is_agg;
32 + * This frames has returned with an IO error,
33 + * so the status report is not intended for this
36 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
39 + wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
40 + ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
41 + pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
42 + is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
45 + * Validate if this TX status report is intended for
46 + * this entry by comparing the WCID/ACK/PID fields.
48 + txwi = rt2800_drv_get_txwi(entry);
50 + word = rt2x00_desc_read(txwi, 1);
51 + tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
52 + tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
53 + tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
55 + if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
56 + rt2x00_dbg(entry->queue->rt2x00dev,
57 + "TX status report missed for queue %d entry %d\n",
58 + entry->queue->qid, entry->entry_idx);
65 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
68 @@ -1059,6 +1100,103 @@ void rt2800_txdone_entry(struct queue_en
70 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
72 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev)
74 + struct data_queue *queue;
75 + struct queue_entry *entry;
80 + while (kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
82 + * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
83 + * guaranteed to be one of the TX QIDs .
85 + qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
86 + queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
88 + if (unlikely(rt2x00queue_empty(queue))) {
89 + rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
94 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
96 + if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
97 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
98 + rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
99 + entry->entry_idx, qid);
103 + match = rt2800_txdone_entry_check(entry, reg);
104 + rt2800_txdone_entry(entry, reg, rt2800_drv_get_txwi(entry), match);
107 +EXPORT_SYMBOL_GPL(rt2800_txdone);
109 +static inline bool rt2800_entry_txstatus_timeout(struct queue_entry *entry)
113 + if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
116 + tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
117 + if (unlikely(tout))
118 + rt2x00_dbg(entry->queue->rt2x00dev,
119 + "TX status timeout for entry %d in queue %d\n",
120 + entry->entry_idx, entry->queue->qid);
125 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
127 + struct data_queue *queue;
128 + struct queue_entry *entry;
130 + tx_queue_for_each(rt2x00dev, queue) {
131 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
132 + if (rt2800_entry_txstatus_timeout(entry))
137 +EXPORT_SYMBOL_GPL(rt2800_txstatus_timeout);
139 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
141 + struct data_queue *queue;
142 + struct queue_entry *entry;
145 + * Process any trailing TX status reports for IO failures,
146 + * we loop until we find the first non-IO error entry. This
147 + * can either be a frame which is free, is being uploaded,
148 + * or has completed the upload but didn't have an entry
149 + * in the TX_STAT_FIFO register yet.
151 + tx_queue_for_each(rt2x00dev, queue) {
152 + while (!rt2x00queue_empty(queue)) {
153 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
155 + if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
156 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
159 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
160 + rt2800_entry_txstatus_timeout(entry))
161 + rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
167 +EXPORT_SYMBOL_GPL(rt2800_txdone_nostatus);
169 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
172 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
173 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
174 @@ -195,6 +195,9 @@ void rt2800_process_rxwi(struct queue_en
176 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
178 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev);
179 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
180 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
182 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
183 void rt2800_clear_beacon(struct queue_entry *entry);
184 --- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
185 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
186 @@ -116,35 +116,6 @@ static bool rt2800usb_txstatus_pending(s
190 -static inline bool rt2800usb_entry_txstatus_timeout(struct queue_entry *entry)
194 - if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
197 - tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
198 - if (unlikely(tout))
199 - rt2x00_dbg(entry->queue->rt2x00dev,
200 - "TX status timeout for entry %d in queue %d\n",
201 - entry->entry_idx, entry->queue->qid);
206 -static bool rt2800usb_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
208 - struct data_queue *queue;
209 - struct queue_entry *entry;
211 - tx_queue_for_each(rt2x00dev, queue) {
212 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
213 - if (rt2800usb_entry_txstatus_timeout(entry))
219 #define TXSTATUS_READ_INTERVAL 1000000
221 static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
222 @@ -171,7 +142,7 @@ static bool rt2800usb_tx_sta_fifo_read_c
225 /* Check if there is any entry that timedout waiting on TX status */
226 - if (rt2800usb_txstatus_timeout(rt2x00dev))
227 + if (rt2800_txstatus_timeout(rt2x00dev))
228 queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
230 if (rt2800usb_txstatus_pending(rt2x00dev)) {
231 @@ -501,123 +472,17 @@ static int rt2800usb_get_tx_data_len(str
233 * TX control handlers
235 -static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
239 - int wcid, ack, pid;
240 - int tx_wcid, tx_ack, tx_pid, is_agg;
243 - * This frames has returned with an IO error,
244 - * so the status report is not intended for this
247 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
250 - wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
251 - ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
252 - pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
253 - is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
256 - * Validate if this TX status report is intended for
257 - * this entry by comparing the WCID/ACK/PID fields.
259 - txwi = rt2800usb_get_txwi(entry);
261 - word = rt2x00_desc_read(txwi, 1);
262 - tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
263 - tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
264 - tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
266 - if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
267 - rt2x00_dbg(entry->queue->rt2x00dev,
268 - "TX status report missed for queue %d entry %d\n",
269 - entry->queue->qid, entry->entry_idx);
276 -static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
278 - struct data_queue *queue;
279 - struct queue_entry *entry;
284 - while (kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
286 - * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
287 - * guaranteed to be one of the TX QIDs .
289 - qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
290 - queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
292 - if (unlikely(rt2x00queue_empty(queue))) {
293 - rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
298 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
300 - if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
301 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
302 - rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
303 - entry->entry_idx, qid);
307 - match = rt2800usb_txdone_entry_check(entry, reg);
308 - rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
312 -static void rt2800usb_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
314 - struct data_queue *queue;
315 - struct queue_entry *entry;
318 - * Process any trailing TX status reports for IO failures,
319 - * we loop until we find the first non-IO error entry. This
320 - * can either be a frame which is free, is being uploaded,
321 - * or has completed the upload but didn't have an entry
322 - * in the TX_STAT_FIFO register yet.
324 - tx_queue_for_each(rt2x00dev, queue) {
325 - while (!rt2x00queue_empty(queue)) {
326 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
328 - if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
329 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
332 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
333 - rt2800usb_entry_txstatus_timeout(entry))
334 - rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
341 static void rt2800usb_work_txdone(struct work_struct *work)
343 struct rt2x00_dev *rt2x00dev =
344 container_of(work, struct rt2x00_dev, txdone_work);
346 while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
347 - rt2800usb_txstatus_timeout(rt2x00dev)) {
348 + rt2800_txstatus_timeout(rt2x00dev)) {
350 - rt2800usb_txdone(rt2x00dev);
351 + rt2800_txdone(rt2x00dev);
353 - rt2800usb_txdone_nostatus(rt2x00dev);
354 + rt2800_txdone_nostatus(rt2x00dev);
357 * The hw may delay sending the packet after DMA complete