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
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>
10 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
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(-)
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
23 if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
24 - tout = msecs_to_jiffies(100);
25 + tout = msecs_to_jiffies(50);
27 tout = msecs_to_jiffies(2000);
29 @@ -1163,15 +1163,13 @@ bool rt2800_txstatus_timeout(struct rt2x
31 struct data_queue *queue;
32 struct queue_entry *entry;
35 - if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
36 - tout = msecs_to_jiffies(50);
38 - tout = msecs_to_jiffies(1000);
39 + if (!test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags)) {
40 + unsigned long tout = msecs_to_jiffies(1000);
42 - if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
44 + if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
48 rt2x00dev->last_nostatus_check = jiffies;
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);
56 -void rt2800mmio_txstatus_tasklet(unsigned long data)
58 - struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
60 - rt2800_txdone(rt2x00dev);
62 - if (rt2800_txstatus_timeout(rt2x00dev))
63 - rt2800_txdone_nostatus(rt2x00dev);
65 - if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
66 - rt2800mmio_enable_interrupt(rt2x00dev,
67 - INT_SOURCE_CSR_TX_FIFO_STATUS);
69 -EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
71 void rt2800mmio_pretbtt_tasklet(unsigned long data)
73 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
74 @@ -270,12 +255,26 @@ void rt2800mmio_autowake_tasklet(unsigne
76 EXPORT_SYMBOL_GPL(rt2800mmio_autowake_tasklet);
78 -static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
79 +static void rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
81 + bool timeout = false;
83 + while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
84 + (timeout = rt2800_txstatus_timeout(rt2x00dev))) {
86 + rt2800_txdone(rt2x00dev);
89 + rt2800_txdone_nostatus(rt2x00dev);
93 +static bool rt2800mmio_fetch_txstatus(struct rt2x00_dev *rt2x00dev)
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).
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.
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);
117 if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
120 - if (!kfifo_put(&rt2x00dev->txstatus_fifo, status)) {
121 - rt2x00_warn(rt2x00dev, "TX status FIFO overrun, drop tx status report\n");
124 + kfifo_put(&rt2x00dev->txstatus_fifo, status);
128 - /* Schedule the tasklet for processing the tx status. */
129 - tasklet_schedule(&rt2x00dev->txstatus_tasklet);
133 +void rt2800mmio_txstatus_tasklet(unsigned long data)
135 + struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
138 + rt2800mmio_txdone(rt2x00dev);
140 + } while (rt2800mmio_fetch_txstatus(rt2x00dev));
142 + if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
143 + rt2800mmio_enable_interrupt(rt2x00dev,
144 + INT_SOURCE_CSR_TX_FIFO_STATUS);
146 +EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
148 irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
150 struct rt2x00_dev *rt2x00dev = dev_instance;
151 @@ -327,8 +338,10 @@ irqreturn_t rt2800mmio_interrupt(int irq
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);
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
166 EXPORT_SYMBOL_GPL(rt2800mmio_kick_queue);
168 +void rt2800mmio_flush_queue(struct data_queue *queue, bool drop)
170 + struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
171 + bool tx_queue = false;
174 + switch (queue->qid) {
187 + for (i = 0; i < 5; i++) {
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.
193 + if (rt2x00queue_empty(queue))
197 + * For TX queues schedule completion tasklet to catch
198 + * tx status timeouts, othewise just wait.
201 + tasklet_disable(&rt2x00dev->txstatus_tasklet);
202 + rt2800mmio_txdone(rt2x00dev);
203 + tasklet_enable(&rt2x00dev->txstatus_tasklet);
207 + * Wait for a little while to give the driver
208 + * the oppurtunity to recover itself.
213 +EXPORT_SYMBOL_GPL(rt2800mmio_flush_queue);
215 void rt2800mmio_stop_queue(struct data_queue *queue)
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
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);
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,