702-rt2800mmio-use-txdone-txstatus-routines-from-lib.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. From 7993486bbab17f8916993710a8660eb47fd991e9 Mon Sep 17 00:00:00 2001
  2. From: Stanislaw Gruszka <[email protected]>
  3. Date: Mon, 9 Jul 2018 16:07:42 +0200
  4. Subject: [PATCH 2/5] rt2800mmio: use txdone/txstatus routines from lib
  5. Use usb txdone/txstatus routines (now in rt2800libc) for mmio devices.
  6. Note this also change how we handle INT_SOURCE_CSR_TX_FIFO_STATUS
  7. interrupt. Now it is disabled since IRQ routine till end of the txstatus
  8. tasklet (the same behaviour like others interrupts). Reason to do not
  9. disable this interrupt was not to miss any tx status from 16 entries
  10. FIFO register. Now, since we check for tx status timeout, we can
  11. allow to miss some tx statuses. However this will be improved in further
  12. patch where I also implement read status FIFO register in the tasklet.
  13. Signed-off-by: Stanislaw Gruszka <[email protected]>
  14. ---
  15. .../net/wireless/ralink/rt2x00/rt2800mmio.c | 180 +-----------------
  16. .../net/wireless/ralink/rt2x00/rt2x00queue.c | 1 +
  17. 2 files changed, 9 insertions(+), 172 deletions(-)
  18. --- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
  19. +++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
  20. @@ -175,161 +175,6 @@ static void rt2800mmio_wakeup(struct rt2
  21. rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
  22. }
  23. -static bool rt2800mmio_txdone_entry_check(struct queue_entry *entry, u32 status)
  24. -{
  25. - __le32 *txwi;
  26. - u32 word;
  27. - int wcid, tx_wcid;
  28. -
  29. - wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
  30. -
  31. - txwi = rt2800_drv_get_txwi(entry);
  32. - word = rt2x00_desc_read(txwi, 1);
  33. - tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
  34. -
  35. - return (tx_wcid == wcid);
  36. -}
  37. -
  38. -static bool rt2800mmio_txdone_find_entry(struct queue_entry *entry, void *data)
  39. -{
  40. - u32 status = *(u32 *)data;
  41. -
  42. - /*
  43. - * rt2800pci hardware might reorder frames when exchanging traffic
  44. - * with multiple BA enabled STAs.
  45. - *
  46. - * For example, a tx queue
  47. - * [ STA1 | STA2 | STA1 | STA2 ]
  48. - * can result in tx status reports
  49. - * [ STA1 | STA1 | STA2 | STA2 ]
  50. - * when the hw decides to aggregate the frames for STA1 into one AMPDU.
  51. - *
  52. - * To mitigate this effect, associate the tx status to the first frame
  53. - * in the tx queue with a matching wcid.
  54. - */
  55. - if (rt2800mmio_txdone_entry_check(entry, status) &&
  56. - !test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
  57. - /*
  58. - * Got a matching frame, associate the tx status with
  59. - * the frame
  60. - */
  61. - entry->status = status;
  62. - set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
  63. - return true;
  64. - }
  65. -
  66. - /* Check the next frame */
  67. - return false;
  68. -}
  69. -
  70. -static bool rt2800mmio_txdone_match_first(struct queue_entry *entry, void *data)
  71. -{
  72. - u32 status = *(u32 *)data;
  73. -
  74. - /*
  75. - * Find the first frame without tx status and assign this status to it
  76. - * regardless if it matches or not.
  77. - */
  78. - if (!test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
  79. - /*
  80. - * Got a matching frame, associate the tx status with
  81. - * the frame
  82. - */
  83. - entry->status = status;
  84. - set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
  85. - return true;
  86. - }
  87. -
  88. - /* Check the next frame */
  89. - return false;
  90. -}
  91. -static bool rt2800mmio_txdone_release_entries(struct queue_entry *entry,
  92. - void *data)
  93. -{
  94. - if (test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
  95. - rt2800_txdone_entry(entry, entry->status,
  96. - rt2800mmio_get_txwi(entry), true);
  97. - return false;
  98. - }
  99. -
  100. - /* No more frames to release */
  101. - return true;
  102. -}
  103. -
  104. -static bool rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
  105. -{
  106. - struct data_queue *queue;
  107. - u32 status;
  108. - u8 qid;
  109. - int max_tx_done = 16;
  110. -
  111. - while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
  112. - qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
  113. - if (unlikely(qid >= QID_RX)) {
  114. - /*
  115. - * Unknown queue, this shouldn't happen. Just drop
  116. - * this tx status.
  117. - */
  118. - rt2x00_warn(rt2x00dev, "Got TX status report with unexpected pid %u, dropping\n",
  119. - qid);
  120. - break;
  121. - }
  122. -
  123. - queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
  124. - if (unlikely(queue == NULL)) {
  125. - /*
  126. - * The queue is NULL, this shouldn't happen. Stop
  127. - * processing here and drop the tx status
  128. - */
  129. - rt2x00_warn(rt2x00dev, "Got TX status for an unavailable queue %u, dropping\n",
  130. - qid);
  131. - break;
  132. - }
  133. -
  134. - if (unlikely(rt2x00queue_empty(queue))) {
  135. - /*
  136. - * The queue is empty. Stop processing here
  137. - * and drop the tx status.
  138. - */
  139. - rt2x00_warn(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
  140. - qid);
  141. - break;
  142. - }
  143. -
  144. - /*
  145. - * Let's associate this tx status with the first
  146. - * matching frame.
  147. - */
  148. - if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
  149. - Q_INDEX, &status,
  150. - rt2800mmio_txdone_find_entry)) {
  151. - /*
  152. - * We cannot match the tx status to any frame, so just
  153. - * use the first one.
  154. - */
  155. - if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
  156. - Q_INDEX, &status,
  157. - rt2800mmio_txdone_match_first)) {
  158. - rt2x00_warn(rt2x00dev, "No frame found for TX status on queue %u, dropping\n",
  159. - qid);
  160. - break;
  161. - }
  162. - }
  163. -
  164. - /*
  165. - * Release all frames with a valid tx status.
  166. - */
  167. - rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
  168. - Q_INDEX, NULL,
  169. - rt2800mmio_txdone_release_entries);
  170. -
  171. - if (--max_tx_done == 0)
  172. - break;
  173. - }
  174. -
  175. - return !max_tx_done;
  176. -}
  177. -
  178. static inline void rt2800mmio_enable_interrupt(struct rt2x00_dev *rt2x00dev,
  179. struct rt2x00_field32 irq_field)
  180. {
  181. @@ -349,14 +194,14 @@ static inline void rt2800mmio_enable_int
  182. void rt2800mmio_txstatus_tasklet(unsigned long data)
  183. {
  184. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  185. - if (rt2800mmio_txdone(rt2x00dev))
  186. - tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  187. - /*
  188. - * No need to enable the tx status interrupt here as we always
  189. - * leave it enabled to minimize the possibility of a tx status
  190. - * register overflow. See comment in interrupt handler.
  191. - */
  192. + rt2800_txdone(rt2x00dev);
  193. +
  194. + rt2800_txdone_nostatus(rt2x00dev);
  195. +
  196. + if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  197. + rt2800mmio_enable_interrupt(rt2x00dev,
  198. + INT_SOURCE_CSR_TX_FIFO_STATUS);
  199. }
  200. EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
  201. @@ -440,10 +285,6 @@ static void rt2800mmio_txstatus_interrup
  202. * because we can schedule the tasklet multiple times (when the
  203. * interrupt fires again during tx status processing).
  204. *
  205. - * Furthermore we don't disable the TX_FIFO_STATUS
  206. - * interrupt here but leave it enabled so that the TX_STA_FIFO
  207. - * can also be read while the tx status tasklet gets executed.
  208. - *
  209. * Since we have only one producer and one consumer we don't
  210. * need to lock the kfifo.
  211. */
  212. @@ -485,13 +326,8 @@ irqreturn_t rt2800mmio_interrupt(int irq
  213. */
  214. mask = ~reg;
  215. - if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
  216. + if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS))
  217. rt2800mmio_txstatus_interrupt(rt2x00dev);
  218. - /*
  219. - * Never disable the TX_FIFO_STATUS interrupt.
  220. - */
  221. - rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
  222. - }
  223. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
  224. tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
  225. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
  226. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
  227. @@ -113,6 +113,7 @@ int rt2x00queue_map_txskb(struct queue_e
  228. return -ENOMEM;
  229. skbdesc->flags |= SKBDESC_DMA_MAPPED_TX;
  230. + rt2x00lib_dmadone(entry);
  231. return 0;
  232. }
  233. EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb);