784fbb16f1f2705f314f8a050c90af17148c8414
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / rt2x00 / 006-rt2800-flush-and-txstatus-rework-for-rt2800mmio.patch
1 From 0240564430c0697d8fde3743d70346a922466b36 Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Wed, 26 Sep 2018 12:24:57 +0200
4 Subject: [PATCH 06/28] rt2800: flush and txstatus rework for rt2800mmio
5
6 Implement custom rt2800mmio flush routine and change txstatus
7 routine to read TX_STA_FIFO also in the tasklet.
8
9 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
10 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
11 ---
12 .../net/wireless/ralink/rt2x00/rt2800lib.c | 14 +--
13 .../net/wireless/ralink/rt2x00/rt2800mmio.c | 118 +++++++++++++-----
14 .../net/wireless/ralink/rt2x00/rt2800mmio.h | 1 +
15 .../net/wireless/ralink/rt2x00/rt2800pci.c | 2 +-
16 4 files changed, 97 insertions(+), 38 deletions(-)
17
18 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
19 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
20 @@ -1147,7 +1147,7 @@ static inline bool rt2800_entry_txstatus
21 return false;
22
23 if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
24 - tout = msecs_to_jiffies(100);
25 + tout = msecs_to_jiffies(50);
26 else
27 tout = msecs_to_jiffies(2000);
28
29 @@ -1163,15 +1163,13 @@ bool rt2800_txstatus_timeout(struct rt2x
30 {
31 struct data_queue *queue;
32 struct queue_entry *entry;
33 - unsigned long tout;
34
35 - if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
36 - tout = msecs_to_jiffies(50);
37 - else
38 - tout = msecs_to_jiffies(1000);
39 + if (!test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags)) {
40 + unsigned long tout = msecs_to_jiffies(1000);
41
42 - if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
43 - return false;
44 + if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
45 + return false;
46 + }
47
48 rt2x00dev->last_nostatus_check = jiffies;
49
50 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
51 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
52 @@ -191,21 +191,6 @@ static inline void rt2800mmio_enable_int
53 spin_unlock_irq(&rt2x00dev->irqmask_lock);
54 }
55
56 -void rt2800mmio_txstatus_tasklet(unsigned long data)
57 -{
58 - struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
59 -
60 - rt2800_txdone(rt2x00dev);
61 -
62 - if (rt2800_txstatus_timeout(rt2x00dev))
63 - rt2800_txdone_nostatus(rt2x00dev);
64 -
65 - if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
66 - rt2800mmio_enable_interrupt(rt2x00dev,
67 - INT_SOURCE_CSR_TX_FIFO_STATUS);
68 -}
69 -EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
70 -
71 void rt2800mmio_pretbtt_tasklet(unsigned long data)
72 {
73 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
74 @@ -270,12 +255,26 @@ void rt2800mmio_autowake_tasklet(unsigne
75 }
76 EXPORT_SYMBOL_GPL(rt2800mmio_autowake_tasklet);
77
78 -static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
79 +static void rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
80 +{
81 + bool timeout = false;
82 +
83 + while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
84 + (timeout = rt2800_txstatus_timeout(rt2x00dev))) {
85 +
86 + rt2800_txdone(rt2x00dev);
87 +
88 + if (timeout)
89 + rt2800_txdone_nostatus(rt2x00dev);
90 + }
91 +}
92 +
93 +static bool rt2800mmio_fetch_txstatus(struct rt2x00_dev *rt2x00dev)
94 {
95 u32 status;
96 - int i;
97 + bool more = false;
98
99 - /*
100 + /* FIXEME: rewrite this comment
101 * The TX_FIFO_STATUS interrupt needs special care. We should
102 * read TX_STA_FIFO but we should do it immediately as otherwise
103 * the register can overflow and we would lose status reports.
104 @@ -286,25 +285,37 @@ static void rt2800mmio_txstatus_interrup
105 * because we can schedule the tasklet multiple times (when the
106 * interrupt fires again during tx status processing).
107 *
108 - * Since we have only one producer and one consumer we don't
109 + * txstatus tasklet is called with INT_SOURCE_CSR_TX_FIFO_STATUS
110 + * disabled so have only one producer and one consumer - we don't
111 * need to lock the kfifo.
112 */
113 - for (i = 0; i < rt2x00dev->tx->limit; i++) {
114 + while (!kfifo_is_full(&rt2x00dev->txstatus_fifo)) {
115 status = rt2x00mmio_register_read(rt2x00dev, TX_STA_FIFO);
116 -
117 if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
118 break;
119
120 - if (!kfifo_put(&rt2x00dev->txstatus_fifo, status)) {
121 - rt2x00_warn(rt2x00dev, "TX status FIFO overrun, drop tx status report\n");
122 - break;
123 - }
124 + kfifo_put(&rt2x00dev->txstatus_fifo, status);
125 + more = true;
126 }
127
128 - /* Schedule the tasklet for processing the tx status. */
129 - tasklet_schedule(&rt2x00dev->txstatus_tasklet);
130 + return more;
131 }
132
133 +void rt2800mmio_txstatus_tasklet(unsigned long data)
134 +{
135 + struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
136 +
137 + do {
138 + rt2800mmio_txdone(rt2x00dev);
139 +
140 + } while (rt2800mmio_fetch_txstatus(rt2x00dev));
141 +
142 + if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
143 + rt2800mmio_enable_interrupt(rt2x00dev,
144 + INT_SOURCE_CSR_TX_FIFO_STATUS);
145 +}
146 +EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
147 +
148 irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
149 {
150 struct rt2x00_dev *rt2x00dev = dev_instance;
151 @@ -327,8 +338,10 @@ irqreturn_t rt2800mmio_interrupt(int irq
152 */
153 mask = ~reg;
154
155 - if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS))
156 - rt2800mmio_txstatus_interrupt(rt2x00dev);
157 + if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
158 + rt2800mmio_fetch_txstatus(rt2x00dev);
159 + tasklet_schedule(&rt2x00dev->txstatus_tasklet);
160 + }
161
162 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
163 tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
164 @@ -453,6 +466,53 @@ void rt2800mmio_kick_queue(struct data_q
165 }
166 EXPORT_SYMBOL_GPL(rt2800mmio_kick_queue);
167
168 +void rt2800mmio_flush_queue(struct data_queue *queue, bool drop)
169 +{
170 + struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
171 + bool tx_queue = false;
172 + unsigned int i;
173 +
174 + switch (queue->qid) {
175 + case QID_AC_VO:
176 + case QID_AC_VI:
177 + case QID_AC_BE:
178 + case QID_AC_BK:
179 + tx_queue = true;
180 + break;
181 + case QID_RX:
182 + break;
183 + default:
184 + return;
185 + }
186 +
187 + for (i = 0; i < 5; i++) {
188 + /*
189 + * Check if the driver is already done, otherwise we
190 + * have to sleep a little while to give the driver/hw
191 + * the oppurtunity to complete interrupt process itself.
192 + */
193 + if (rt2x00queue_empty(queue))
194 + break;
195 +
196 + /*
197 + * For TX queues schedule completion tasklet to catch
198 + * tx status timeouts, othewise just wait.
199 + */
200 + if (tx_queue) {
201 + tasklet_disable(&rt2x00dev->txstatus_tasklet);
202 + rt2800mmio_txdone(rt2x00dev);
203 + tasklet_enable(&rt2x00dev->txstatus_tasklet);
204 + }
205 +
206 + /*
207 + * Wait for a little while to give the driver
208 + * the oppurtunity to recover itself.
209 + */
210 + msleep(50);
211 + }
212 +}
213 +EXPORT_SYMBOL_GPL(rt2800mmio_flush_queue);
214 +
215 void rt2800mmio_stop_queue(struct data_queue *queue)
216 {
217 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
218 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.h
219 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.h
220 @@ -148,6 +148,7 @@ void rt2800mmio_toggle_irq(struct rt2x00
221 /* Queue handlers */
222 void rt2800mmio_start_queue(struct data_queue *queue);
223 void rt2800mmio_kick_queue(struct data_queue *queue);
224 +void rt2800mmio_flush_queue(struct data_queue *queue, bool drop);
225 void rt2800mmio_stop_queue(struct data_queue *queue);
226 void rt2800mmio_queue_init(struct data_queue *queue);
227
228 --- a/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
229 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
230 @@ -364,7 +364,7 @@ static const struct rt2x00lib_ops rt2800
231 .start_queue = rt2800mmio_start_queue,
232 .kick_queue = rt2800mmio_kick_queue,
233 .stop_queue = rt2800mmio_stop_queue,
234 - .flush_queue = rt2x00mmio_flush_queue,
235 + .flush_queue = rt2800mmio_flush_queue,
236 .write_tx_desc = rt2800mmio_write_tx_desc,
237 .write_tx_data = rt2800_write_tx_data,
238 .write_beacon = rt2800_write_beacon,