1 From 175c2548332b45b144af673e70fdbb1a947d7aba Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Sat, 9 Feb 2019 12:08:35 +0100
4 Subject: [PATCH 25/28] rt2800mmio: use timer and work for handling tx statuses
7 Sometimes we can get into situation when there are pending statuses,
8 but we do not get INT_SOURCE_CSR_TX_FIFO_STATUS. Handle this situation
9 by arming timeout timer and read statuses (it will fix case when
10 we just do not have irq) and queue work to handle case we missed
11 statues from hardware FIFO.
13 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
15 .../net/wireless/ralink/rt2x00/rt2800mmio.c | 81 +++++++++++++++++--
16 .../net/wireless/ralink/rt2x00/rt2800mmio.h | 1 +
17 .../net/wireless/ralink/rt2x00/rt2800pci.c | 2 +-
18 .../net/wireless/ralink/rt2x00/rt2800soc.c | 2 +-
19 .../net/wireless/ralink/rt2x00/rt2x00dev.c | 4 +
20 5 files changed, 82 insertions(+), 8 deletions(-)
22 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
23 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
24 @@ -426,6 +426,9 @@ void rt2800mmio_start_queue(struct data_
26 EXPORT_SYMBOL_GPL(rt2800mmio_start_queue);
29 +#define TXSTATUS_TIMEOUT 200000000
31 void rt2800mmio_kick_queue(struct data_queue *queue)
33 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
34 @@ -440,6 +443,8 @@ void rt2800mmio_kick_queue(struct data_q
35 entry = rt2x00queue_get_entry(queue, Q_INDEX);
36 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX(queue->qid),
38 + hrtimer_start(&rt2x00dev->txstatus_timer,
39 + TXSTATUS_TIMEOUT, HRTIMER_MODE_REL);
42 entry = rt2x00queue_get_entry(queue, Q_INDEX);
43 @@ -484,12 +489,8 @@ void rt2800mmio_flush_queue(struct data_
44 * For TX queues schedule completion tasklet to catch
45 * tx status timeouts, othewise just wait.
48 - tasklet_disable(&rt2x00dev->txstatus_tasklet);
49 - rt2800_txdone(rt2x00dev, UINT_MAX);
50 - rt2800_txdone_nostatus(rt2x00dev);
51 - tasklet_enable(&rt2x00dev->txstatus_tasklet);
54 + queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
57 * Wait for a little while to give the driver
58 @@ -627,6 +628,10 @@ void rt2800mmio_clear_entry(struct queue
59 word = rt2x00_desc_read(entry_priv->desc, 1);
60 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1);
61 rt2x00_desc_write(entry_priv->desc, 1, word);
63 + /* If last entry stop txstatus timer */
64 + if (entry->queue->length == 1)
65 + hrtimer_cancel(&rt2x00dev->txstatus_timer);
68 EXPORT_SYMBOL_GPL(rt2800mmio_clear_entry);
69 @@ -759,6 +764,70 @@ int rt2800mmio_enable_radio(struct rt2x0
71 EXPORT_SYMBOL_GPL(rt2800mmio_enable_radio);
73 +static void rt2800mmio_work_txdone(struct work_struct *work)
75 + struct rt2x00_dev *rt2x00dev =
76 + container_of(work, struct rt2x00_dev, txdone_work);
78 + if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
81 + while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
82 + rt2800_txstatus_timeout(rt2x00dev)) {
84 + tasklet_disable(&rt2x00dev->txstatus_tasklet);
85 + rt2800_txdone(rt2x00dev, UINT_MAX);
86 + rt2800_txdone_nostatus(rt2x00dev);
87 + tasklet_enable(&rt2x00dev->txstatus_tasklet);
90 + if (rt2800_txstatus_pending(rt2x00dev))
91 + hrtimer_start(&rt2x00dev->txstatus_timer,
92 + TXSTATUS_TIMEOUT, HRTIMER_MODE_REL);
95 +static enum hrtimer_restart rt2800mmio_tx_sta_fifo_timeout(struct hrtimer *timer)
97 + struct rt2x00_dev *rt2x00dev =
98 + container_of(timer, struct rt2x00_dev, txstatus_timer);
100 + if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
103 + if (!rt2800_txstatus_pending(rt2x00dev))
106 + rt2800mmio_fetch_txstatus(rt2x00dev);
107 + if (!kfifo_is_empty(&rt2x00dev->txstatus_fifo))
108 + tasklet_schedule(&rt2x00dev->txstatus_tasklet);
110 + queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
112 + return HRTIMER_NORESTART;
115 +int rt2800mmio_probe_hw(struct rt2x00_dev *rt2x00dev)
119 + retval = rt2800_probe_hw(rt2x00dev);
124 + * Set txstatus timer function.
126 + rt2x00dev->txstatus_timer.function = rt2800mmio_tx_sta_fifo_timeout;
129 + * Overwrite TX done handler
131 + INIT_WORK(&rt2x00dev->txdone_work, rt2800mmio_work_txdone);
135 +EXPORT_SYMBOL_GPL(rt2800mmio_probe_hw);
137 MODULE_AUTHOR(DRV_PROJECT);
138 MODULE_VERSION(DRV_VERSION);
139 MODULE_DESCRIPTION("rt2800 MMIO library");
140 --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.h
141 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.h
142 @@ -153,6 +153,7 @@ void rt2800mmio_stop_queue(struct data_q
143 void rt2800mmio_queue_init(struct data_queue *queue);
145 /* Initialization functions */
146 +int rt2800mmio_probe_hw(struct rt2x00_dev *rt2x00dev);
147 bool rt2800mmio_get_entry_state(struct queue_entry *entry);
148 void rt2800mmio_clear_entry(struct queue_entry *entry);
149 int rt2800mmio_init_queues(struct rt2x00_dev *rt2x00dev);
150 --- a/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
151 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
152 @@ -346,7 +346,7 @@ static const struct rt2x00lib_ops rt2800
153 .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
154 .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
155 .autowake_tasklet = rt2800mmio_autowake_tasklet,
156 - .probe_hw = rt2800_probe_hw,
157 + .probe_hw = rt2800mmio_probe_hw,
158 .get_firmware_name = rt2800pci_get_firmware_name,
159 .check_firmware = rt2800_check_firmware,
160 .load_firmware = rt2800_load_firmware,
161 --- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
162 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
163 @@ -185,7 +185,7 @@ static const struct rt2x00lib_ops rt2800
164 .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
165 .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
166 .autowake_tasklet = rt2800mmio_autowake_tasklet,
167 - .probe_hw = rt2800_probe_hw,
168 + .probe_hw = rt2800mmio_probe_hw,
169 .get_firmware_name = rt2800soc_get_firmware_name,
170 .check_firmware = rt2800soc_check_firmware,
171 .load_firmware = rt2800soc_load_firmware,
172 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
173 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
174 @@ -1391,6 +1391,8 @@ int rt2x00lib_probe_dev(struct rt2x00_de
175 mutex_init(&rt2x00dev->conf_mutex);
176 INIT_LIST_HEAD(&rt2x00dev->bar_list);
177 spin_lock_init(&rt2x00dev->bar_list_lock);
178 + hrtimer_init(&rt2x00dev->txstatus_timer, CLOCK_MONOTONIC,
181 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
183 @@ -1515,6 +1517,8 @@ void rt2x00lib_remove_dev(struct rt2x00_
184 cancel_delayed_work_sync(&rt2x00dev->autowakeup_work);
185 cancel_work_sync(&rt2x00dev->sleep_work);
187 + hrtimer_cancel(&rt2x00dev->txstatus_timer);
190 * Kill the tx status tasklet.