a883258a4c684e4ac2699674c48aaabf0f353717
[openwrt/staging/xback.git] /
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
5 rt2800lib
6
7 In order to reuse usb txdone/txstatus routines for mmio, move them
8 to common rt2800lib.c file.
9
10 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
11 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
12 ---
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(-)
17
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;
22 }
23
24 +static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg)
25 +{
26 + __le32 *txwi;
27 + u32 word;
28 + int wcid, ack, pid;
29 + int tx_wcid, tx_ack, tx_pid, is_agg;
30 +
31 + /*
32 + * This frames has returned with an IO error,
33 + * so the status report is not intended for this
34 + * frame.
35 + */
36 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
37 + return false;
38 +
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);
43 +
44 + /*
45 + * Validate if this TX status report is intended for
46 + * this entry by comparing the WCID/ACK/PID fields.
47 + */
48 + txwi = rt2800_drv_get_txwi(entry);
49 +
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);
54 +
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);
59 + return false;
60 + }
61 +
62 + return true;
63 +}
64 +
65 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
66 bool match)
67 {
68 @@ -1059,6 +1100,103 @@ void rt2800_txdone_entry(struct queue_en
69 }
70 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
71
72 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev)
73 +{
74 + struct data_queue *queue;
75 + struct queue_entry *entry;
76 + u32 reg;
77 + u8 qid;
78 + bool match;
79 +
80 + while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
81 + /*
82 + * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
83 + * guaranteed to be one of the TX QIDs .
84 + */
85 + qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
86 + queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
87 +
88 + if (unlikely(rt2x00queue_empty(queue))) {
89 + rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
90 + qid);
91 + break;
92 + }
93 +
94 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
95 +
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);
100 + break;
101 + }
102 +
103 + match = rt2800_txdone_entry_check(entry, reg);
104 + rt2800_txdone_entry(entry, reg, rt2800_drv_get_txwi(entry), match);
105 + }
106 +}
107 +EXPORT_SYMBOL_GPL(rt2800_txdone);
108 +
109 +static inline bool rt2800_entry_txstatus_timeout(struct queue_entry *entry)
110 +{
111 + bool tout;
112 +
113 + if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
114 + return false;
115 +
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);
121 + return tout;
122 +
123 +}
124 +
125 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
126 +{
127 + struct data_queue *queue;
128 + struct queue_entry *entry;
129 +
130 + tx_queue_for_each(rt2x00dev, queue) {
131 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
132 + if (rt2800_entry_txstatus_timeout(entry))
133 + return true;
134 + }
135 + return false;
136 +}
137 +EXPORT_SYMBOL_GPL(rt2800_txstatus_timeout);
138 +
139 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
140 +{
141 + struct data_queue *queue;
142 + struct queue_entry *entry;
143 +
144 + /*
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.
150 + */
151 + tx_queue_for_each(rt2x00dev, queue) {
152 + while (!rt2x00queue_empty(queue)) {
153 + entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
154 +
155 + if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
156 + !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
157 + break;
158 +
159 + if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
160 + rt2800_entry_txstatus_timeout(entry))
161 + rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
162 + else
163 + break;
164 + }
165 + }
166 +}
167 +EXPORT_SYMBOL_GPL(rt2800_txdone_nostatus);
168 +
169 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
170 unsigned int index)
171 {
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
175
176 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
177 bool match);
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);
181
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
187 return false;
188 }
189
190 -static inline bool rt2800usb_entry_txstatus_timeout(struct queue_entry *entry)
191 -{
192 - bool tout;
193 -
194 - if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
195 - return false;
196 -
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);
202 - return tout;
203 -
204 -}
205 -
206 -static bool rt2800usb_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
207 -{
208 - struct data_queue *queue;
209 - struct queue_entry *entry;
210 -
211 - tx_queue_for_each(rt2x00dev, queue) {
212 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
213 - if (rt2800usb_entry_txstatus_timeout(entry))
214 - return true;
215 - }
216 - return false;
217 -}
218 -
219 #define TXSTATUS_READ_INTERVAL 1000000
220
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
223 }
224
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);
229
230 if (rt2800usb_txstatus_pending(rt2x00dev)) {
231 @@ -501,123 +472,17 @@ static int rt2800usb_get_tx_data_len(str
232 /*
233 * TX control handlers
234 */
235 -static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
236 -{
237 - __le32 *txwi;
238 - u32 word;
239 - int wcid, ack, pid;
240 - int tx_wcid, tx_ack, tx_pid, is_agg;
241 -
242 - /*
243 - * This frames has returned with an IO error,
244 - * so the status report is not intended for this
245 - * frame.
246 - */
247 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
248 - return false;
249 -
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);
254 -
255 - /*
256 - * Validate if this TX status report is intended for
257 - * this entry by comparing the WCID/ACK/PID fields.
258 - */
259 - txwi = rt2800usb_get_txwi(entry);
260 -
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);
265 -
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);
270 - return false;
271 - }
272 -
273 - return true;
274 -}
275 -
276 -static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
277 -{
278 - struct data_queue *queue;
279 - struct queue_entry *entry;
280 - u32 reg;
281 - u8 qid;
282 - bool match;
283 -
284 - while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
285 - /*
286 - * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
287 - * guaranteed to be one of the TX QIDs .
288 - */
289 - qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
290 - queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
291 -
292 - if (unlikely(rt2x00queue_empty(queue))) {
293 - rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
294 - qid);
295 - break;
296 - }
297 -
298 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
299 -
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);
304 - break;
305 - }
306 -
307 - match = rt2800usb_txdone_entry_check(entry, reg);
308 - rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
309 - }
310 -}
311 -
312 -static void rt2800usb_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
313 -{
314 - struct data_queue *queue;
315 - struct queue_entry *entry;
316 -
317 - /*
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.
323 - */
324 - tx_queue_for_each(rt2x00dev, queue) {
325 - while (!rt2x00queue_empty(queue)) {
326 - entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
327 -
328 - if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
329 - !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
330 - break;
331 -
332 - if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
333 - rt2800usb_entry_txstatus_timeout(entry))
334 - rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
335 - else
336 - break;
337 - }
338 - }
339 -}
340 -
341 static void rt2800usb_work_txdone(struct work_struct *work)
342 {
343 struct rt2x00_dev *rt2x00dev =
344 container_of(work, struct rt2x00_dev, txdone_work);
345
346 while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
347 - rt2800usb_txstatus_timeout(rt2x00dev)) {
348 + rt2800_txstatus_timeout(rt2x00dev)) {
349
350 - rt2800usb_txdone(rt2x00dev);
351 + rt2800_txdone(rt2x00dev);
352
353 - rt2800usb_txdone_nostatus(rt2x00dev);
354 + rt2800_txdone_nostatus(rt2x00dev);
355
356 /*
357 * The hw may delay sending the packet after DMA complete