Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / package / kernel / mac80211 / patches / rt2x00 / 705-rt2800-flush-and-txstatus-rework-for-rt2800mmio.patch
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
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 ---
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(-)
16
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
20                 return false;
21  
22         if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
23 -               tout = msecs_to_jiffies(100);
24 +               tout = msecs_to_jiffies(50);
25         else
26                 tout = msecs_to_jiffies(2000);
27  
28 @@ -1166,15 +1166,13 @@ bool rt2800_txstatus_timeout(struct rt2x
29  {
30         struct data_queue *queue;
31         struct queue_entry *entry;
32 -       unsigned long tout;
33  
34 -       if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
35 -               tout = msecs_to_jiffies(50);
36 -       else
37 -               tout = msecs_to_jiffies(1000);
38 +       if (!test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags)) {
39 +               unsigned long tout = msecs_to_jiffies(1000);
40  
41 -       if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
42 -               return false;
43 +               if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
44 +                       return false;
45 +       }
46  
47         rt2x00dev->last_nostatus_check = jiffies;
48  
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);
53  }
54  
55 -void rt2800mmio_txstatus_tasklet(unsigned long data)
56 -{
57 -       struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
58 -
59 -       rt2800_txdone(rt2x00dev);
60 -
61 -       if (rt2800_txstatus_timeout(rt2x00dev))
62 -               rt2800_txdone_nostatus(rt2x00dev);
63 -
64 -       if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
65 -               rt2800mmio_enable_interrupt(rt2x00dev,
66 -                                           INT_SOURCE_CSR_TX_FIFO_STATUS);
67 -}
68 -EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
69 -
70  void rt2800mmio_pretbtt_tasklet(unsigned long data)
71  {
72         struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
73 @@ -270,12 +255,26 @@ void rt2800mmio_autowake_tasklet(unsigne
74  }
75  EXPORT_SYMBOL_GPL(rt2800mmio_autowake_tasklet);
76  
77 -static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
78 +static void rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
79 +{
80 +       bool timeout = false;
81 +
82 +       while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
83 +              (timeout = rt2800_txstatus_timeout(rt2x00dev))) {
84 +
85 +               rt2800_txdone(rt2x00dev);
86 +
87 +               if (timeout)
88 +                       rt2800_txdone_nostatus(rt2x00dev);
89 +       }
90 +}
91 +
92 +static bool rt2800mmio_fetch_txstatus(struct rt2x00_dev *rt2x00dev)
93  {
94         u32 status;
95 -       int i;
96 +       bool more = false;
97  
98 -       /*
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).
106          *
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.
111          */
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);
115 -
116                 if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
117                         break;
118  
119 -               if (!kfifo_put(&rt2x00dev->txstatus_fifo, status)) {
120 -                       rt2x00_warn(rt2x00dev, "TX status FIFO overrun, drop tx status report\n");
121 -                       break;
122 -               }
123 +               kfifo_put(&rt2x00dev->txstatus_fifo, status);
124 +               more = true;
125         }
126  
127 -       /* Schedule the tasklet for processing the tx status. */
128 -       tasklet_schedule(&rt2x00dev->txstatus_tasklet);
129 +       return more;
130  }
131  
132 +void rt2800mmio_txstatus_tasklet(unsigned long data)
133 +{
134 +       struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
135 +
136 +       do {
137 +               rt2800mmio_txdone(rt2x00dev);
138 +
139 +       } while (rt2800mmio_fetch_txstatus(rt2x00dev));
140 +
141 +       if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
142 +               rt2800mmio_enable_interrupt(rt2x00dev,
143 +                                           INT_SOURCE_CSR_TX_FIFO_STATUS);
144 +}
145 +EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
146 +
147  irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
148  {
149         struct rt2x00_dev *rt2x00dev = dev_instance;
150 @@ -327,8 +338,10 @@ irqreturn_t rt2800mmio_interrupt(int irq
151          */
152         mask = ~reg;
153  
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);
159 +       }
160  
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
164  }
165  EXPORT_SYMBOL_GPL(rt2800mmio_kick_queue);
166  
167 +void rt2800mmio_flush_queue(struct data_queue *queue, bool drop)
168 +{
169 +       struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
170 +       bool tx_queue = false;
171 +       unsigned int i;
172 +
173 +       //printk("FLUSH queue %d len %d drop %d\n", queue->qid, queue->length, drop);
174 +
175 +       switch (queue->qid) {
176 +       case QID_AC_VO:
177 +       case QID_AC_VI:
178 +       case QID_AC_BE:
179 +       case QID_AC_BK:
180 +               tx_queue = true;
181 +               break;
182 +       case QID_RX:
183 +               break;
184 +       default:
185 +               return;
186 +       }
187 +
188 +       for (i = 0; i < 5; i++) {
189 +               /*
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.
193 +                */
194 +               if (rt2x00queue_empty(queue))
195 +                       break;
196 +
197 +               /*
198 +                * For TX queues schedule completion tasklet to catch
199 +                * tx status timeouts, othewise just wait.
200 +                */
201 +               if (tx_queue) {
202 +                       tasklet_disable(&rt2x00dev->txstatus_tasklet);
203 +                       rt2800mmio_txdone(rt2x00dev);
204 +                       tasklet_enable(&rt2x00dev->txstatus_tasklet);
205 +               } 
206 +
207 +               /*
208 +                * Wait for a little while to give the driver
209 +                * the oppurtunity to recover itself.
210 +                */
211 +               msleep(50);
212 +       }
213 +}
214 +EXPORT_SYMBOL_GPL(rt2800mmio_flush_queue);
215 +
216  void rt2800mmio_stop_queue(struct data_queue *queue)
217  {
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
222  /* Queue handlers */
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);
228  
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,