dma.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef B43legacy_DMA_H_
  3. #define B43legacy_DMA_H_
  4. #include <linux/list.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/workqueue.h>
  7. #include <linux/linkage.h>
  8. #include <linux/atomic.h>
  9. #include "b43legacy.h"
  10. /* DMA-Interrupt reasons. */
  11. #define B43legacy_DMAIRQ_FATALMASK ((1 << 10) | (1 << 11) | (1 << 12) \
  12. | (1 << 14) | (1 << 15))
  13. #define B43legacy_DMAIRQ_NONFATALMASK (1 << 13)
  14. #define B43legacy_DMAIRQ_RX_DONE (1 << 16)
  15. /*** 32-bit DMA Engine. ***/
  16. /* 32-bit DMA controller registers. */
  17. #define B43legacy_DMA32_TXCTL 0x00
  18. #define B43legacy_DMA32_TXENABLE 0x00000001
  19. #define B43legacy_DMA32_TXSUSPEND 0x00000002
  20. #define B43legacy_DMA32_TXLOOPBACK 0x00000004
  21. #define B43legacy_DMA32_TXFLUSH 0x00000010
  22. #define B43legacy_DMA32_TXADDREXT_MASK 0x00030000
  23. #define B43legacy_DMA32_TXADDREXT_SHIFT 16
  24. #define B43legacy_DMA32_TXRING 0x04
  25. #define B43legacy_DMA32_TXINDEX 0x08
  26. #define B43legacy_DMA32_TXSTATUS 0x0C
  27. #define B43legacy_DMA32_TXDPTR 0x00000FFF
  28. #define B43legacy_DMA32_TXSTATE 0x0000F000
  29. #define B43legacy_DMA32_TXSTAT_DISABLED 0x00000000
  30. #define B43legacy_DMA32_TXSTAT_ACTIVE 0x00001000
  31. #define B43legacy_DMA32_TXSTAT_IDLEWAIT 0x00002000
  32. #define B43legacy_DMA32_TXSTAT_STOPPED 0x00003000
  33. #define B43legacy_DMA32_TXSTAT_SUSP 0x00004000
  34. #define B43legacy_DMA32_TXERROR 0x000F0000
  35. #define B43legacy_DMA32_TXERR_NOERR 0x00000000
  36. #define B43legacy_DMA32_TXERR_PROT 0x00010000
  37. #define B43legacy_DMA32_TXERR_UNDERRUN 0x00020000
  38. #define B43legacy_DMA32_TXERR_BUFREAD 0x00030000
  39. #define B43legacy_DMA32_TXERR_DESCREAD 0x00040000
  40. #define B43legacy_DMA32_TXACTIVE 0xFFF00000
  41. #define B43legacy_DMA32_RXCTL 0x10
  42. #define B43legacy_DMA32_RXENABLE 0x00000001
  43. #define B43legacy_DMA32_RXFROFF_MASK 0x000000FE
  44. #define B43legacy_DMA32_RXFROFF_SHIFT 1
  45. #define B43legacy_DMA32_RXDIRECTFIFO 0x00000100
  46. #define B43legacy_DMA32_RXADDREXT_MASK 0x00030000
  47. #define B43legacy_DMA32_RXADDREXT_SHIFT 16
  48. #define B43legacy_DMA32_RXRING 0x14
  49. #define B43legacy_DMA32_RXINDEX 0x18
  50. #define B43legacy_DMA32_RXSTATUS 0x1C
  51. #define B43legacy_DMA32_RXDPTR 0x00000FFF
  52. #define B43legacy_DMA32_RXSTATE 0x0000F000
  53. #define B43legacy_DMA32_RXSTAT_DISABLED 0x00000000
  54. #define B43legacy_DMA32_RXSTAT_ACTIVE 0x00001000
  55. #define B43legacy_DMA32_RXSTAT_IDLEWAIT 0x00002000
  56. #define B43legacy_DMA32_RXSTAT_STOPPED 0x00003000
  57. #define B43legacy_DMA32_RXERROR 0x000F0000
  58. #define B43legacy_DMA32_RXERR_NOERR 0x00000000
  59. #define B43legacy_DMA32_RXERR_PROT 0x00010000
  60. #define B43legacy_DMA32_RXERR_OVERFLOW 0x00020000
  61. #define B43legacy_DMA32_RXERR_BUFWRITE 0x00030000
  62. #define B43legacy_DMA32_RXERR_DESCREAD 0x00040000
  63. #define B43legacy_DMA32_RXACTIVE 0xFFF00000
  64. /* 32-bit DMA descriptor. */
  65. struct b43legacy_dmadesc32 {
  66. __le32 control;
  67. __le32 address;
  68. } __packed;
  69. #define B43legacy_DMA32_DCTL_BYTECNT 0x00001FFF
  70. #define B43legacy_DMA32_DCTL_ADDREXT_MASK 0x00030000
  71. #define B43legacy_DMA32_DCTL_ADDREXT_SHIFT 16
  72. #define B43legacy_DMA32_DCTL_DTABLEEND 0x10000000
  73. #define B43legacy_DMA32_DCTL_IRQ 0x20000000
  74. #define B43legacy_DMA32_DCTL_FRAMEEND 0x40000000
  75. #define B43legacy_DMA32_DCTL_FRAMESTART 0x80000000
  76. /* Misc DMA constants */
  77. #define B43legacy_DMA_RINGMEMSIZE PAGE_SIZE
  78. #define B43legacy_DMA0_RX_FRAMEOFFSET 30
  79. #define B43legacy_DMA3_RX_FRAMEOFFSET 0
  80. /* DMA engine tuning knobs */
  81. #define B43legacy_TXRING_SLOTS 128
  82. #define B43legacy_RXRING_SLOTS 64
  83. #define B43legacy_DMA0_RX_BUFFERSIZE (2304 + 100)
  84. #define B43legacy_DMA3_RX_BUFFERSIZE 16
  85. #ifdef CONFIG_B43LEGACY_DMA
  86. struct sk_buff;
  87. struct b43legacy_private;
  88. struct b43legacy_txstatus;
  89. struct b43legacy_dmadesc_meta {
  90. /* The kernel DMA-able buffer. */
  91. struct sk_buff *skb;
  92. /* DMA base bus-address of the descriptor buffer. */
  93. dma_addr_t dmaaddr;
  94. /* ieee80211 TX status. Only used once per 802.11 frag. */
  95. bool is_last_fragment;
  96. };
  97. enum b43legacy_dmatype {
  98. B43legacy_DMA_30BIT = 30,
  99. B43legacy_DMA_32BIT = 32,
  100. };
  101. struct b43legacy_dmaring {
  102. /* Kernel virtual base address of the ring memory. */
  103. void *descbase;
  104. /* Meta data about all descriptors. */
  105. struct b43legacy_dmadesc_meta *meta;
  106. /* Cache of TX headers for each slot.
  107. * This is to avoid an allocation on each TX.
  108. * This is NULL for an RX ring.
  109. */
  110. u8 *txhdr_cache;
  111. /* (Unadjusted) DMA base bus-address of the ring memory. */
  112. dma_addr_t dmabase;
  113. /* Number of descriptor slots in the ring. */
  114. int nr_slots;
  115. /* Number of used descriptor slots. */
  116. int used_slots;
  117. /* Currently used slot in the ring. */
  118. int current_slot;
  119. /* Frameoffset in octets. */
  120. u32 frameoffset;
  121. /* Descriptor buffer size. */
  122. u16 rx_buffersize;
  123. /* The MMIO base register of the DMA controller. */
  124. u16 mmio_base;
  125. /* DMA controller index number (0-5). */
  126. int index;
  127. /* Boolean. Is this a TX ring? */
  128. bool tx;
  129. /* The type of DMA engine used. */
  130. enum b43legacy_dmatype type;
  131. /* Boolean. Is this ring stopped at ieee80211 level? */
  132. bool stopped;
  133. /* The QOS priority assigned to this ring. Only used for TX rings.
  134. * This is the mac80211 "queue" value. */
  135. u8 queue_prio;
  136. struct b43legacy_wldev *dev;
  137. #ifdef CONFIG_B43LEGACY_DEBUG
  138. /* Maximum number of used slots. */
  139. int max_used_slots;
  140. /* Last time we injected a ring overflow. */
  141. unsigned long last_injected_overflow;
  142. #endif /* CONFIG_B43LEGACY_DEBUG*/
  143. };
  144. static inline
  145. u32 b43legacy_dma_read(struct b43legacy_dmaring *ring,
  146. u16 offset)
  147. {
  148. return b43legacy_read32(ring->dev, ring->mmio_base + offset);
  149. }
  150. static inline
  151. void b43legacy_dma_write(struct b43legacy_dmaring *ring,
  152. u16 offset, u32 value)
  153. {
  154. b43legacy_write32(ring->dev, ring->mmio_base + offset, value);
  155. }
  156. int b43legacy_dma_init(struct b43legacy_wldev *dev);
  157. void b43legacy_dma_free(struct b43legacy_wldev *dev);
  158. void b43legacy_dma_tx_suspend(struct b43legacy_wldev *dev);
  159. void b43legacy_dma_tx_resume(struct b43legacy_wldev *dev);
  160. int b43legacy_dma_tx(struct b43legacy_wldev *dev,
  161. struct sk_buff *skb);
  162. void b43legacy_dma_handle_txstatus(struct b43legacy_wldev *dev,
  163. const struct b43legacy_txstatus *status);
  164. void b43legacy_dma_rx(struct b43legacy_dmaring *ring);
  165. #else /* CONFIG_B43LEGACY_DMA */
  166. static inline
  167. int b43legacy_dma_init(struct b43legacy_wldev *dev)
  168. {
  169. return 0;
  170. }
  171. static inline
  172. void b43legacy_dma_free(struct b43legacy_wldev *dev)
  173. {
  174. }
  175. static inline
  176. int b43legacy_dma_tx(struct b43legacy_wldev *dev,
  177. struct sk_buff *skb)
  178. {
  179. return 0;
  180. }
  181. static inline
  182. void b43legacy_dma_handle_txstatus(struct b43legacy_wldev *dev,
  183. const struct b43legacy_txstatus *status)
  184. {
  185. }
  186. static inline
  187. void b43legacy_dma_rx(struct b43legacy_dmaring *ring)
  188. {
  189. }
  190. static inline
  191. void b43legacy_dma_tx_suspend(struct b43legacy_wldev *dev)
  192. {
  193. }
  194. static inline
  195. void b43legacy_dma_tx_resume(struct b43legacy_wldev *dev)
  196. {
  197. }
  198. #endif /* CONFIG_B43LEGACY_DMA */
  199. #endif /* B43legacy_DMA_H_ */