006-rt2800-flush-and-txstatus-rework-for-rt2800mmio.patch 7.4 KB

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