b5e4cfe9bb926728edf24d3411359034bb777f44
[openwrt/staging/dedeckeh.git] / package / kernel / mac80211 / patches / rt2x00 / 702-rt2800mmio-use-txdone-txstatus-routines-from-lib.patch
1 From 7993486bbab17f8916993710a8660eb47fd991e9 Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Mon, 9 Jul 2018 16:07:42 +0200
4 Subject: [PATCH 2/5] rt2800mmio: use txdone/txstatus routines from lib
5
6 Use usb txdone/txstatus routines (now in rt2800libc) for mmio devices.
7
8 Note this also change how we handle INT_SOURCE_CSR_TX_FIFO_STATUS
9 interrupt. Now it is disabled since IRQ routine till end of the txstatus
10 tasklet (the same behaviour like others interrupts). Reason to do not
11 disable this interrupt was not to miss any tx status from 16 entries
12 FIFO register. Now, since we check for tx status timeout, we can
13 allow to miss some tx statuses. However this will be improved in further
14 patch where I also implement read status FIFO register in the tasklet.
15
16 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
17 ---
18 .../net/wireless/ralink/rt2x00/rt2800mmio.c | 180 +-----------------
19 .../net/wireless/ralink/rt2x00/rt2x00queue.c | 1 +
20 2 files changed, 9 insertions(+), 172 deletions(-)
21
22 diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
23 index e1a7ed7e4892..aa8449a5e8fe 100644
24 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
25 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
26 @@ -175,161 +175,6 @@ static void rt2800mmio_wakeup(struct rt2x00_dev *rt2x00dev)
27 rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
28 }
29
30 -static bool rt2800mmio_txdone_entry_check(struct queue_entry *entry, u32 status)
31 -{
32 - __le32 *txwi;
33 - u32 word;
34 - int wcid, tx_wcid;
35 -
36 - wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
37 -
38 - txwi = rt2800_drv_get_txwi(entry);
39 - word = rt2x00_desc_read(txwi, 1);
40 - tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
41 -
42 - return (tx_wcid == wcid);
43 -}
44 -
45 -static bool rt2800mmio_txdone_find_entry(struct queue_entry *entry, void *data)
46 -{
47 - u32 status = *(u32 *)data;
48 -
49 - /*
50 - * rt2800pci hardware might reorder frames when exchanging traffic
51 - * with multiple BA enabled STAs.
52 - *
53 - * For example, a tx queue
54 - * [ STA1 | STA2 | STA1 | STA2 ]
55 - * can result in tx status reports
56 - * [ STA1 | STA1 | STA2 | STA2 ]
57 - * when the hw decides to aggregate the frames for STA1 into one AMPDU.
58 - *
59 - * To mitigate this effect, associate the tx status to the first frame
60 - * in the tx queue with a matching wcid.
61 - */
62 - if (rt2800mmio_txdone_entry_check(entry, status) &&
63 - !test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
64 - /*
65 - * Got a matching frame, associate the tx status with
66 - * the frame
67 - */
68 - entry->status = status;
69 - set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
70 - return true;
71 - }
72 -
73 - /* Check the next frame */
74 - return false;
75 -}
76 -
77 -static bool rt2800mmio_txdone_match_first(struct queue_entry *entry, void *data)
78 -{
79 - u32 status = *(u32 *)data;
80 -
81 - /*
82 - * Find the first frame without tx status and assign this status to it
83 - * regardless if it matches or not.
84 - */
85 - if (!test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
86 - /*
87 - * Got a matching frame, associate the tx status with
88 - * the frame
89 - */
90 - entry->status = status;
91 - set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
92 - return true;
93 - }
94 -
95 - /* Check the next frame */
96 - return false;
97 -}
98 -static bool rt2800mmio_txdone_release_entries(struct queue_entry *entry,
99 - void *data)
100 -{
101 - if (test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
102 - rt2800_txdone_entry(entry, entry->status,
103 - rt2800mmio_get_txwi(entry), true);
104 - return false;
105 - }
106 -
107 - /* No more frames to release */
108 - return true;
109 -}
110 -
111 -static bool rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
112 -{
113 - struct data_queue *queue;
114 - u32 status;
115 - u8 qid;
116 - int max_tx_done = 16;
117 -
118 - while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
119 - qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
120 - if (unlikely(qid >= QID_RX)) {
121 - /*
122 - * Unknown queue, this shouldn't happen. Just drop
123 - * this tx status.
124 - */
125 - rt2x00_warn(rt2x00dev, "Got TX status report with unexpected pid %u, dropping\n",
126 - qid);
127 - break;
128 - }
129 -
130 - queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
131 - if (unlikely(queue == NULL)) {
132 - /*
133 - * The queue is NULL, this shouldn't happen. Stop
134 - * processing here and drop the tx status
135 - */
136 - rt2x00_warn(rt2x00dev, "Got TX status for an unavailable queue %u, dropping\n",
137 - qid);
138 - break;
139 - }
140 -
141 - if (unlikely(rt2x00queue_empty(queue))) {
142 - /*
143 - * The queue is empty. Stop processing here
144 - * and drop the tx status.
145 - */
146 - rt2x00_warn(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
147 - qid);
148 - break;
149 - }
150 -
151 - /*
152 - * Let's associate this tx status with the first
153 - * matching frame.
154 - */
155 - if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
156 - Q_INDEX, &status,
157 - rt2800mmio_txdone_find_entry)) {
158 - /*
159 - * We cannot match the tx status to any frame, so just
160 - * use the first one.
161 - */
162 - if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
163 - Q_INDEX, &status,
164 - rt2800mmio_txdone_match_first)) {
165 - rt2x00_warn(rt2x00dev, "No frame found for TX status on queue %u, dropping\n",
166 - qid);
167 - break;
168 - }
169 - }
170 -
171 - /*
172 - * Release all frames with a valid tx status.
173 - */
174 - rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
175 - Q_INDEX, NULL,
176 - rt2800mmio_txdone_release_entries);
177 -
178 - if (--max_tx_done == 0)
179 - break;
180 - }
181 -
182 - return !max_tx_done;
183 -}
184 -
185 static inline void rt2800mmio_enable_interrupt(struct rt2x00_dev *rt2x00dev,
186 struct rt2x00_field32 irq_field)
187 {
188 @@ -349,14 +194,14 @@ static inline void rt2800mmio_enable_interrupt(struct rt2x00_dev *rt2x00dev,
189 void rt2800mmio_txstatus_tasklet(unsigned long data)
190 {
191 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
192 - if (rt2800mmio_txdone(rt2x00dev))
193 - tasklet_schedule(&rt2x00dev->txstatus_tasklet);
194
195 - /*
196 - * No need to enable the tx status interrupt here as we always
197 - * leave it enabled to minimize the possibility of a tx status
198 - * register overflow. See comment in interrupt handler.
199 - */
200 + rt2800_txdone(rt2x00dev);
201 +
202 + rt2800_txdone_nostatus(rt2x00dev);
203 +
204 + if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
205 + rt2800mmio_enable_interrupt(rt2x00dev,
206 + INT_SOURCE_CSR_TX_FIFO_STATUS);
207 }
208 EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
209
210 @@ -440,10 +285,6 @@ static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
211 * because we can schedule the tasklet multiple times (when the
212 * interrupt fires again during tx status processing).
213 *
214 - * Furthermore we don't disable the TX_FIFO_STATUS
215 - * interrupt here but leave it enabled so that the TX_STA_FIFO
216 - * can also be read while the tx status tasklet gets executed.
217 - *
218 * Since we have only one producer and one consumer we don't
219 * need to lock the kfifo.
220 */
221 @@ -485,13 +326,8 @@ irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
222 */
223 mask = ~reg;
224
225 - if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
226 + if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS))
227 rt2800mmio_txstatus_interrupt(rt2x00dev);
228 - /*
229 - * Never disable the TX_FIFO_STATUS interrupt.
230 - */
231 - rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
232 - }
233
234 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
235 tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
236 diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
237 index 710e9641552e..6e8beb7ea350 100644
238 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
239 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
240 @@ -113,6 +113,7 @@ int rt2x00queue_map_txskb(struct queue_entry *entry)
241 return -ENOMEM;
242
243 skbdesc->flags |= SKBDESC_DMA_MAPPED_TX;
244 + rt2x00lib_dmadone(entry);
245 return 0;
246 }
247 EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb);
248 --
249 2.18.0
250