dma.h 6.7 KB

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