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