028-rt2800mmio-use-timer-and-work-for-handling-tx-status.patch 6.7 KB

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