025-rt2800mmio-use-timer-and-work-for-handling-tx-status.patch 6.5 KB

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