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

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