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 diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
18 index a567bc273ffc..9f2835729016 100644
19 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
20 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
21 @@ -957,6 +957,47 @@ static void rt2800_rate_from_status(struct skb_frame_desc *skbdesc,
22 skbdesc->tx_rate_flags = flags;
25 +static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg)
30 + int tx_wcid, tx_ack, tx_pid, is_agg;
33 + * This frames has returned with an IO error,
34 + * so the status report is not intended for this
37 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
40 + wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
41 + ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
42 + pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
43 + is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
46 + * Validate if this TX status report is intended for
47 + * this entry by comparing the WCID/ACK/PID fields.
49 + txwi = rt2800_drv_get_txwi(entry);
51 + word = rt2x00_desc_read(txwi, 1);
52 + tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
53 + tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
54 + tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
56 + if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
57 + rt2x00_dbg(entry->queue->rt2x00dev,
58 + "TX status report missed for queue %d entry %d\n",
59 + entry->queue->qid, entry->entry_idx);
66 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
69 @@ -1059,6 +1100,103 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
71 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
73 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev)
75 + struct data_queue *queue;
76 + struct queue_entry *entry;
81 + while (kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
83 + * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
84 + * guaranteed to be one of the TX QIDs .
86 + qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
87 + queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
89 + if (unlikely(rt2x00queue_empty(queue))) {
90 + rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
95 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
97 + if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
98 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
99 + rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
100 + entry->entry_idx, qid);
104 + match = rt2800_txdone_entry_check(entry, reg);
105 + rt2800_txdone_entry(entry, reg, rt2800_drv_get_txwi(entry), match);
108 +EXPORT_SYMBOL_GPL(rt2800_txdone);
110 +static inline bool rt2800_entry_txstatus_timeout(struct queue_entry *entry)
114 + if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
117 + tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
118 + if (unlikely(tout))
119 + rt2x00_dbg(entry->queue->rt2x00dev,
120 + "TX status timeout for entry %d in queue %d\n",
121 + entry->entry_idx, entry->queue->qid);
126 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
128 + struct data_queue *queue;
129 + struct queue_entry *entry;
131 + tx_queue_for_each(rt2x00dev, queue) {
132 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
133 + if (rt2800_entry_txstatus_timeout(entry))
138 +EXPORT_SYMBOL_GPL(rt2800_txstatus_timeout);
140 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
142 + struct data_queue *queue;
143 + struct queue_entry *entry;
146 + * Process any trailing TX status reports for IO failures,
147 + * we loop until we find the first non-IO error entry. This
148 + * can either be a frame which is free, is being uploaded,
149 + * or has completed the upload but didn't have an entry
150 + * in the TX_STAT_FIFO register yet.
152 + tx_queue_for_each(rt2x00dev, queue) {
153 + while (!rt2x00queue_empty(queue)) {
154 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
156 + if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
157 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
160 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
161 + rt2800_entry_txstatus_timeout(entry))
162 + rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
168 +EXPORT_SYMBOL_GPL(rt2800_txdone_nostatus);
170 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
173 diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
174 index 51d9c2a932cc..0dff2c7b3010 100644
175 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
176 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
177 @@ -195,6 +195,9 @@ void rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *tx
179 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
181 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev);
182 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
183 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
185 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
186 void rt2800_clear_beacon(struct queue_entry *entry);
187 diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
188 index 98a7313fea4a..19eabf16147b 100644
189 --- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
190 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
191 @@ -116,35 +116,6 @@ static bool rt2800usb_txstatus_pending(struct rt2x00_dev *rt2x00dev)
195 -static inline bool rt2800usb_entry_txstatus_timeout(struct queue_entry *entry)
199 - if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
202 - tout = time_after(jiffies, entry->last_action + msecs_to_jiffies(500));
203 - if (unlikely(tout))
204 - rt2x00_dbg(entry->queue->rt2x00dev,
205 - "TX status timeout for entry %d in queue %d\n",
206 - entry->entry_idx, entry->queue->qid);
211 -static bool rt2800usb_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
213 - struct data_queue *queue;
214 - struct queue_entry *entry;
216 - tx_queue_for_each(rt2x00dev, queue) {
217 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
218 - if (rt2800usb_entry_txstatus_timeout(entry))
224 #define TXSTATUS_READ_INTERVAL 1000000
226 static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
227 @@ -171,7 +142,7 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
230 /* Check if there is any entry that timedout waiting on TX status */
231 - if (rt2800usb_txstatus_timeout(rt2x00dev))
232 + if (rt2800_txstatus_timeout(rt2x00dev))
233 queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
235 if (rt2800usb_txstatus_pending(rt2x00dev)) {
236 @@ -501,123 +472,17 @@ static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
238 * TX control handlers
240 -static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
244 - int wcid, ack, pid;
245 - int tx_wcid, tx_ack, tx_pid, is_agg;
248 - * This frames has returned with an IO error,
249 - * so the status report is not intended for this
252 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
255 - wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
256 - ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
257 - pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
258 - is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
261 - * Validate if this TX status report is intended for
262 - * this entry by comparing the WCID/ACK/PID fields.
264 - txwi = rt2800usb_get_txwi(entry);
266 - word = rt2x00_desc_read(txwi, 1);
267 - tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
268 - tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
269 - tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
271 - if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
272 - rt2x00_dbg(entry->queue->rt2x00dev,
273 - "TX status report missed for queue %d entry %d\n",
274 - entry->queue->qid, entry->entry_idx);
281 -static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
283 - struct data_queue *queue;
284 - struct queue_entry *entry;
289 - while (kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
291 - * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
292 - * guaranteed to be one of the TX QIDs .
294 - qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
295 - queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
297 - if (unlikely(rt2x00queue_empty(queue))) {
298 - rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
303 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
305 - if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
306 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
307 - rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
308 - entry->entry_idx, qid);
312 - match = rt2800usb_txdone_entry_check(entry, reg);
313 - rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
317 -static void rt2800usb_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
319 - struct data_queue *queue;
320 - struct queue_entry *entry;
323 - * Process any trailing TX status reports for IO failures,
324 - * we loop until we find the first non-IO error entry. This
325 - * can either be a frame which is free, is being uploaded,
326 - * or has completed the upload but didn't have an entry
327 - * in the TX_STAT_FIFO register yet.
329 - tx_queue_for_each(rt2x00dev, queue) {
330 - while (!rt2x00queue_empty(queue)) {
331 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
333 - if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
334 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
337 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
338 - rt2800usb_entry_txstatus_timeout(entry))
339 - rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
346 static void rt2800usb_work_txdone(struct work_struct *work)
348 struct rt2x00_dev *rt2x00dev =
349 container_of(work, struct rt2x00_dev, txdone_work);
351 while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
352 - rt2800usb_txstatus_timeout(rt2x00dev)) {
353 + rt2800_txstatus_timeout(rt2x00dev)) {
355 - rt2800usb_txdone(rt2x00dev);
356 + rt2800_txdone(rt2x00dev);
358 - rt2800usb_txdone_nostatus(rt2x00dev);
359 + rt2800_txdone_nostatus(rt2x00dev);
362 * The hw may delay sending the packet after DMA complete