5d69b5db3074562b63da87551c0692c0829c11d1
[oweals/openwrt.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 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;
23  }
24  
25 +static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg)
26 +{
27 +       __le32 *txwi;
28 +       u32 word;
29 +       int wcid, ack, pid;
30 +       int tx_wcid, tx_ack, tx_pid, is_agg;
31 +
32 +       /*
33 +        * This frames has returned with an IO error,
34 +        * so the status report is not intended for this
35 +        * frame.
36 +        */
37 +       if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
38 +               return false;
39 +
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);
44 +
45 +       /*
46 +        * Validate if this TX status report is intended for
47 +        * this entry by comparing the WCID/ACK/PID fields.
48 +        */
49 +       txwi = rt2800_drv_get_txwi(entry);
50 +
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);
55 +
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);
60 +               return false;
61 +       }
62 +
63 +       return true;
64 +}
65 +
66  void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
67                          bool match)
68  {
69 @@ -1059,6 +1100,103 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
70  }
71  EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
72  
73 +void rt2800_txdone(struct rt2x00_dev *rt2x00dev)
74 +{
75 +       struct data_queue *queue;
76 +       struct queue_entry *entry;
77 +       u32 reg;
78 +       u8 qid;
79 +       bool match;
80 +
81 +       while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
82 +               /*
83 +                * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
84 +                * guaranteed to be one of the TX QIDs .
85 +                */
86 +               qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
87 +               queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
88 +
89 +               if (unlikely(rt2x00queue_empty(queue))) {
90 +                       rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
91 +                                  qid);
92 +                       break;
93 +               }
94 +
95 +               entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
96 +
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);
101 +                       break;
102 +               }
103 +
104 +               match = rt2800_txdone_entry_check(entry, reg);
105 +               rt2800_txdone_entry(entry, reg, rt2800_drv_get_txwi(entry), match);
106 +       }
107 +}
108 +EXPORT_SYMBOL_GPL(rt2800_txdone);
109 +
110 +static inline bool rt2800_entry_txstatus_timeout(struct queue_entry *entry)
111 +{
112 +       bool tout;
113 +
114 +       if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
115 +               return false;
116 +
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);
122 +       return tout;
123 +
124 +}
125 +
126 +bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
127 +{
128 +       struct data_queue *queue;
129 +       struct queue_entry *entry;
130 +
131 +       tx_queue_for_each(rt2x00dev, queue) {
132 +               entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
133 +               if (rt2800_entry_txstatus_timeout(entry))
134 +                       return true;
135 +       }
136 +       return false;
137 +}
138 +EXPORT_SYMBOL_GPL(rt2800_txstatus_timeout);
139 +
140 +void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
141 +{
142 +       struct data_queue *queue;
143 +       struct queue_entry *entry;
144 +
145 +       /*
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.
151 +        */
152 +       tx_queue_for_each(rt2x00dev, queue) {
153 +               while (!rt2x00queue_empty(queue)) {
154 +                       entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
155 +
156 +                       if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
157 +                           !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
158 +                               break;
159 +
160 +                       if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
161 +                           rt2800_entry_txstatus_timeout(entry))
162 +                               rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
163 +                       else
164 +                               break;
165 +               }
166 +       }
167 +}
168 +EXPORT_SYMBOL_GPL(rt2800_txdone_nostatus);
169 +
170  static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
171                                           unsigned int index)
172  {
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
178  
179  void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
180                          bool match);
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);
184  
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)
192         return false;
193  }
194  
195 -static inline bool rt2800usb_entry_txstatus_timeout(struct queue_entry *entry)
196 -{
197 -       bool tout;
198 -
199 -       if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
200 -               return false;
201 -
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);
207 -       return tout;
208 -
209 -}
210 -
211 -static bool rt2800usb_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
212 -{
213 -       struct data_queue *queue;
214 -       struct queue_entry *entry;
215 -
216 -       tx_queue_for_each(rt2x00dev, queue) {
217 -               entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
218 -               if (rt2800usb_entry_txstatus_timeout(entry))
219 -                       return true;
220 -       }
221 -       return false;
222 -}
223 -
224  #define TXSTATUS_READ_INTERVAL 1000000
225  
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,
228         }
229  
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);
234  
235         if (rt2800usb_txstatus_pending(rt2x00dev)) {
236 @@ -501,123 +472,17 @@ static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
237  /*
238   * TX control handlers
239   */
240 -static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
241 -{
242 -       __le32 *txwi;
243 -       u32 word;
244 -       int wcid, ack, pid;
245 -       int tx_wcid, tx_ack, tx_pid, is_agg;
246 -
247 -       /*
248 -        * This frames has returned with an IO error,
249 -        * so the status report is not intended for this
250 -        * frame.
251 -        */
252 -       if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
253 -               return false;
254 -
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);
259 -
260 -       /*
261 -        * Validate if this TX status report is intended for
262 -        * this entry by comparing the WCID/ACK/PID fields.
263 -        */
264 -       txwi = rt2800usb_get_txwi(entry);
265 -
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);
270 -
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);
275 -               return false;
276 -       }
277 -
278 -       return true;
279 -}
280 -
281 -static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
282 -{
283 -       struct data_queue *queue;
284 -       struct queue_entry *entry;
285 -       u32 reg;
286 -       u8 qid;
287 -       bool match;
288 -
289 -       while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
290 -               /*
291 -                * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
292 -                * guaranteed to be one of the TX QIDs .
293 -                */
294 -               qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
295 -               queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
296 -
297 -               if (unlikely(rt2x00queue_empty(queue))) {
298 -                       rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
299 -                                  qid);
300 -                       break;
301 -               }
302 -
303 -               entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
304 -
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);
309 -                       break;
310 -               }
311 -
312 -               match = rt2800usb_txdone_entry_check(entry, reg);
313 -               rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
314 -       }
315 -}
316 -
317 -static void rt2800usb_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
318 -{
319 -       struct data_queue *queue;
320 -       struct queue_entry *entry;
321 -
322 -       /*
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.
328 -        */
329 -       tx_queue_for_each(rt2x00dev, queue) {
330 -               while (!rt2x00queue_empty(queue)) {
331 -                       entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
332 -
333 -                       if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
334 -                           !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
335 -                               break;
336 -
337 -                       if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
338 -                           rt2800usb_entry_txstatus_timeout(entry))
339 -                               rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
340 -                       else
341 -                               break;
342 -               }
343 -       }
344 -}
345 -
346  static void rt2800usb_work_txdone(struct work_struct *work)
347  {
348         struct rt2x00_dev *rt2x00dev =
349             container_of(work, struct rt2x00_dev, txdone_work);
350  
351         while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
352 -              rt2800usb_txstatus_timeout(rt2x00dev)) {
353 +              rt2800_txstatus_timeout(rt2x00dev)) {
354  
355 -               rt2800usb_txdone(rt2x00dev);
356 +               rt2800_txdone(rt2x00dev);
357  
358 -               rt2800usb_txdone_nostatus(rt2x00dev);
359 +               rt2800_txdone_nostatus(rt2x00dev);
360  
361                 /*
362                  * The hw may delay sending the packet after DMA complete
363 -- 
364 2.18.0
365