1 From 0d9fbb738a5eadc7abc8060f43ebcc71f6324c07 Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Tue, 14 Aug 2018 08:58:48 +0200
4 Subject: [PATCH 5/5] rt2800: flush and txstatus rework for rt2800mmio
6 Implement custom rt2800mmio flush routine and change txstatus
7 routine to read TX_STA_FIFO also in the tasklet.
9 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
11 .../net/wireless/ralink/rt2x00/rt2800lib.c | 14 +-
12 .../net/wireless/ralink/rt2x00/rt2800mmio.c | 120 +++++++++++++-----
13 .../net/wireless/ralink/rt2x00/rt2800mmio.h | 1 +
14 .../net/wireless/ralink/rt2x00/rt2800pci.c | 2 +-
15 4 files changed, 99 insertions(+), 38 deletions(-)
17 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
18 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
19 @@ -1150,7 +1150,7 @@ static inline bool rt2800_entry_txstatus
22 if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
23 - tout = msecs_to_jiffies(100);
24 + tout = msecs_to_jiffies(50);
26 tout = msecs_to_jiffies(2000);
28 @@ -1166,15 +1166,13 @@ bool rt2800_txstatus_timeout(struct rt2x
30 struct data_queue *queue;
31 struct queue_entry *entry;
34 - if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
35 - tout = msecs_to_jiffies(50);
37 - tout = msecs_to_jiffies(1000);
38 + if (!test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags)) {
39 + unsigned long tout = msecs_to_jiffies(1000);
41 - if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
43 + if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
47 rt2x00dev->last_nostatus_check = jiffies;
49 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
50 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
51 @@ -191,21 +191,6 @@ static inline void rt2800mmio_enable_int
52 spin_unlock_irq(&rt2x00dev->irqmask_lock);
55 -void rt2800mmio_txstatus_tasklet(unsigned long data)
57 - struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
59 - rt2800_txdone(rt2x00dev);
61 - if (rt2800_txstatus_timeout(rt2x00dev))
62 - rt2800_txdone_nostatus(rt2x00dev);
64 - if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
65 - rt2800mmio_enable_interrupt(rt2x00dev,
66 - INT_SOURCE_CSR_TX_FIFO_STATUS);
68 -EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
70 void rt2800mmio_pretbtt_tasklet(unsigned long data)
72 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
73 @@ -270,12 +255,26 @@ void rt2800mmio_autowake_tasklet(unsigne
75 EXPORT_SYMBOL_GPL(rt2800mmio_autowake_tasklet);
77 -static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
78 +static void rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
80 + bool timeout = false;
82 + while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
83 + (timeout = rt2800_txstatus_timeout(rt2x00dev))) {
85 + rt2800_txdone(rt2x00dev);
88 + rt2800_txdone_nostatus(rt2x00dev);
92 +static bool rt2800mmio_fetch_txstatus(struct rt2x00_dev *rt2x00dev)
99 + /* FIXEME: rewrite this comment
100 * The TX_FIFO_STATUS interrupt needs special care. We should
101 * read TX_STA_FIFO but we should do it immediately as otherwise
102 * the register can overflow and we would lose status reports.
103 @@ -286,25 +285,37 @@ static void rt2800mmio_txstatus_interrup
104 * because we can schedule the tasklet multiple times (when the
105 * interrupt fires again during tx status processing).
107 - * Since we have only one producer and one consumer we don't
108 + * txstatus tasklet is called with INT_SOURCE_CSR_TX_FIFO_STATUS
109 + * disabled so have only one producer and one consumer - we don't
110 * need to lock the kfifo.
112 - for (i = 0; i < rt2x00dev->tx->limit; i++) {
113 + while (!kfifo_is_full(&rt2x00dev->txstatus_fifo)) {
114 status = rt2x00mmio_register_read(rt2x00dev, TX_STA_FIFO);
116 if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
119 - if (!kfifo_put(&rt2x00dev->txstatus_fifo, status)) {
120 - rt2x00_warn(rt2x00dev, "TX status FIFO overrun, drop tx status report\n");
123 + kfifo_put(&rt2x00dev->txstatus_fifo, status);
127 - /* Schedule the tasklet for processing the tx status. */
128 - tasklet_schedule(&rt2x00dev->txstatus_tasklet);
132 +void rt2800mmio_txstatus_tasklet(unsigned long data)
134 + struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
137 + rt2800mmio_txdone(rt2x00dev);
139 + } while (rt2800mmio_fetch_txstatus(rt2x00dev));
141 + if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
142 + rt2800mmio_enable_interrupt(rt2x00dev,
143 + INT_SOURCE_CSR_TX_FIFO_STATUS);
145 +EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
147 irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
149 struct rt2x00_dev *rt2x00dev = dev_instance;
150 @@ -327,8 +338,10 @@ irqreturn_t rt2800mmio_interrupt(int irq
154 - if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS))
155 - rt2800mmio_txstatus_interrupt(rt2x00dev);
156 + if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
157 + rt2800mmio_fetch_txstatus(rt2x00dev);
158 + tasklet_schedule(&rt2x00dev->txstatus_tasklet);
161 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
162 tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
163 @@ -453,6 +466,55 @@ void rt2800mmio_kick_queue(struct data_q
165 EXPORT_SYMBOL_GPL(rt2800mmio_kick_queue);
167 +void rt2800mmio_flush_queue(struct data_queue *queue, bool drop)
169 + struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
170 + bool tx_queue = false;
173 + //printk("FLUSH queue %d len %d drop %d\n", queue->qid, queue->length, drop);
175 + switch (queue->qid) {
188 + for (i = 0; i < 5; i++) {
190 + * Check if the driver is already done, otherwise we
191 + * have to sleep a little while to give the driver/hw
192 + * the oppurtunity to complete interrupt process itself.
194 + if (rt2x00queue_empty(queue))
198 + * For TX queues schedule completion tasklet to catch
199 + * tx status timeouts, othewise just wait.
202 + tasklet_disable(&rt2x00dev->txstatus_tasklet);
203 + rt2800mmio_txdone(rt2x00dev);
204 + tasklet_enable(&rt2x00dev->txstatus_tasklet);
208 + * Wait for a little while to give the driver
209 + * the oppurtunity to recover itself.
214 +EXPORT_SYMBOL_GPL(rt2800mmio_flush_queue);
216 void rt2800mmio_stop_queue(struct data_queue *queue)
218 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
219 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.h
220 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.h
221 @@ -148,6 +148,7 @@ void rt2800mmio_toggle_irq(struct rt2x00
223 void rt2800mmio_start_queue(struct data_queue *queue);
224 void rt2800mmio_kick_queue(struct data_queue *queue);
225 +void rt2800mmio_flush_queue(struct data_queue *queue, bool drop);
226 void rt2800mmio_stop_queue(struct data_queue *queue);
227 void rt2800mmio_queue_init(struct data_queue *queue);
229 --- a/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
230 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
231 @@ -364,7 +364,7 @@ static const struct rt2x00lib_ops rt2800
232 .start_queue = rt2800mmio_start_queue,
233 .kick_queue = rt2800mmio_kick_queue,
234 .stop_queue = rt2800mmio_stop_queue,
235 - .flush_queue = rt2x00mmio_flush_queue,
236 + .flush_queue = rt2800mmio_flush_queue,
237 .write_tx_desc = rt2800mmio_write_tx_desc,
238 .write_tx_data = rt2800_write_tx_data,
239 .write_beacon = rt2800_write_beacon,