dma.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef B43_DMA_H_
  3. #define B43_DMA_H_
  4. #include <linux/err.h>
  5. #include "b43.h"
  6. /* DMA-Interrupt reasons. */
  7. #define B43_DMAIRQ_FATALMASK ((1 << 10) | (1 << 11) | (1 << 12) \
  8. | (1 << 14) | (1 << 15))
  9. #define B43_DMAIRQ_RDESC_UFLOW (1 << 13)
  10. #define B43_DMAIRQ_RX_DONE (1 << 16)
  11. /*** 32-bit DMA Engine. ***/
  12. /* 32-bit DMA controller registers. */
  13. #define B43_DMA32_TXCTL 0x00
  14. #define B43_DMA32_TXENABLE 0x00000001
  15. #define B43_DMA32_TXSUSPEND 0x00000002
  16. #define B43_DMA32_TXLOOPBACK 0x00000004
  17. #define B43_DMA32_TXFLUSH 0x00000010
  18. #define B43_DMA32_TXPARITYDISABLE 0x00000800
  19. #define B43_DMA32_TXADDREXT_MASK 0x00030000
  20. #define B43_DMA32_TXADDREXT_SHIFT 16
  21. #define B43_DMA32_TXRING 0x04
  22. #define B43_DMA32_TXINDEX 0x08
  23. #define B43_DMA32_TXSTATUS 0x0C
  24. #define B43_DMA32_TXDPTR 0x00000FFF
  25. #define B43_DMA32_TXSTATE 0x0000F000
  26. #define B43_DMA32_TXSTAT_DISABLED 0x00000000
  27. #define B43_DMA32_TXSTAT_ACTIVE 0x00001000
  28. #define B43_DMA32_TXSTAT_IDLEWAIT 0x00002000
  29. #define B43_DMA32_TXSTAT_STOPPED 0x00003000
  30. #define B43_DMA32_TXSTAT_SUSP 0x00004000
  31. #define B43_DMA32_TXERROR 0x000F0000
  32. #define B43_DMA32_TXERR_NOERR 0x00000000
  33. #define B43_DMA32_TXERR_PROT 0x00010000
  34. #define B43_DMA32_TXERR_UNDERRUN 0x00020000
  35. #define B43_DMA32_TXERR_BUFREAD 0x00030000
  36. #define B43_DMA32_TXERR_DESCREAD 0x00040000
  37. #define B43_DMA32_TXACTIVE 0xFFF00000
  38. #define B43_DMA32_RXCTL 0x10
  39. #define B43_DMA32_RXENABLE 0x00000001
  40. #define B43_DMA32_RXFROFF_MASK 0x000000FE
  41. #define B43_DMA32_RXFROFF_SHIFT 1
  42. #define B43_DMA32_RXDIRECTFIFO 0x00000100
  43. #define B43_DMA32_RXPARITYDISABLE 0x00000800
  44. #define B43_DMA32_RXADDREXT_MASK 0x00030000
  45. #define B43_DMA32_RXADDREXT_SHIFT 16
  46. #define B43_DMA32_RXRING 0x14
  47. #define B43_DMA32_RXINDEX 0x18
  48. #define B43_DMA32_RXSTATUS 0x1C
  49. #define B43_DMA32_RXDPTR 0x00000FFF
  50. #define B43_DMA32_RXSTATE 0x0000F000
  51. #define B43_DMA32_RXSTAT_DISABLED 0x00000000
  52. #define B43_DMA32_RXSTAT_ACTIVE 0x00001000
  53. #define B43_DMA32_RXSTAT_IDLEWAIT 0x00002000
  54. #define B43_DMA32_RXSTAT_STOPPED 0x00003000
  55. #define B43_DMA32_RXERROR 0x000F0000
  56. #define B43_DMA32_RXERR_NOERR 0x00000000
  57. #define B43_DMA32_RXERR_PROT 0x00010000
  58. #define B43_DMA32_RXERR_OVERFLOW 0x00020000
  59. #define B43_DMA32_RXERR_BUFWRITE 0x00030000
  60. #define B43_DMA32_RXERR_DESCREAD 0x00040000
  61. #define B43_DMA32_RXACTIVE 0xFFF00000
  62. /* 32-bit DMA descriptor. */
  63. struct b43_dmadesc32 {
  64. __le32 control;
  65. __le32 address;
  66. } __packed;
  67. #define B43_DMA32_DCTL_BYTECNT 0x00001FFF
  68. #define B43_DMA32_DCTL_ADDREXT_MASK 0x00030000
  69. #define B43_DMA32_DCTL_ADDREXT_SHIFT 16
  70. #define B43_DMA32_DCTL_DTABLEEND 0x10000000
  71. #define B43_DMA32_DCTL_IRQ 0x20000000
  72. #define B43_DMA32_DCTL_FRAMEEND 0x40000000
  73. #define B43_DMA32_DCTL_FRAMESTART 0x80000000
  74. /*** 64-bit DMA Engine. ***/
  75. /* 64-bit DMA controller registers. */
  76. #define B43_DMA64_TXCTL 0x00
  77. #define B43_DMA64_TXENABLE 0x00000001
  78. #define B43_DMA64_TXSUSPEND 0x00000002
  79. #define B43_DMA64_TXLOOPBACK 0x00000004
  80. #define B43_DMA64_TXFLUSH 0x00000010
  81. #define B43_DMA64_TXPARITYDISABLE 0x00000800
  82. #define B43_DMA64_TXADDREXT_MASK 0x00030000
  83. #define B43_DMA64_TXADDREXT_SHIFT 16
  84. #define B43_DMA64_TXINDEX 0x04
  85. #define B43_DMA64_TXRINGLO 0x08
  86. #define B43_DMA64_TXRINGHI 0x0C
  87. #define B43_DMA64_TXSTATUS 0x10
  88. #define B43_DMA64_TXSTATDPTR 0x00001FFF
  89. #define B43_DMA64_TXSTAT 0xF0000000
  90. #define B43_DMA64_TXSTAT_DISABLED 0x00000000
  91. #define B43_DMA64_TXSTAT_ACTIVE 0x10000000
  92. #define B43_DMA64_TXSTAT_IDLEWAIT 0x20000000
  93. #define B43_DMA64_TXSTAT_STOPPED 0x30000000
  94. #define B43_DMA64_TXSTAT_SUSP 0x40000000
  95. #define B43_DMA64_TXERROR 0x14
  96. #define B43_DMA64_TXERRDPTR 0x0001FFFF
  97. #define B43_DMA64_TXERR 0xF0000000
  98. #define B43_DMA64_TXERR_NOERR 0x00000000
  99. #define B43_DMA64_TXERR_PROT 0x10000000
  100. #define B43_DMA64_TXERR_UNDERRUN 0x20000000
  101. #define B43_DMA64_TXERR_TRANSFER 0x30000000
  102. #define B43_DMA64_TXERR_DESCREAD 0x40000000
  103. #define B43_DMA64_TXERR_CORE 0x50000000
  104. #define B43_DMA64_RXCTL 0x20
  105. #define B43_DMA64_RXENABLE 0x00000001
  106. #define B43_DMA64_RXFROFF_MASK 0x000000FE
  107. #define B43_DMA64_RXFROFF_SHIFT 1
  108. #define B43_DMA64_RXDIRECTFIFO 0x00000100
  109. #define B43_DMA64_RXPARITYDISABLE 0x00000800
  110. #define B43_DMA64_RXADDREXT_MASK 0x00030000
  111. #define B43_DMA64_RXADDREXT_SHIFT 16
  112. #define B43_DMA64_RXINDEX 0x24
  113. #define B43_DMA64_RXRINGLO 0x28
  114. #define B43_DMA64_RXRINGHI 0x2C
  115. #define B43_DMA64_RXSTATUS 0x30
  116. #define B43_DMA64_RXSTATDPTR 0x00001FFF
  117. #define B43_DMA64_RXSTAT 0xF0000000
  118. #define B43_DMA64_RXSTAT_DISABLED 0x00000000
  119. #define B43_DMA64_RXSTAT_ACTIVE 0x10000000
  120. #define B43_DMA64_RXSTAT_IDLEWAIT 0x20000000
  121. #define B43_DMA64_RXSTAT_STOPPED 0x30000000
  122. #define B43_DMA64_RXSTAT_SUSP 0x40000000
  123. #define B43_DMA64_RXERROR 0x34
  124. #define B43_DMA64_RXERRDPTR 0x0001FFFF
  125. #define B43_DMA64_RXERR 0xF0000000
  126. #define B43_DMA64_RXERR_NOERR 0x00000000
  127. #define B43_DMA64_RXERR_PROT 0x10000000
  128. #define B43_DMA64_RXERR_UNDERRUN 0x20000000
  129. #define B43_DMA64_RXERR_TRANSFER 0x30000000
  130. #define B43_DMA64_RXERR_DESCREAD 0x40000000
  131. #define B43_DMA64_RXERR_CORE 0x50000000
  132. /* 64-bit DMA descriptor. */
  133. struct b43_dmadesc64 {
  134. __le32 control0;
  135. __le32 control1;
  136. __le32 address_low;
  137. __le32 address_high;
  138. } __packed;
  139. #define B43_DMA64_DCTL0_DTABLEEND 0x10000000
  140. #define B43_DMA64_DCTL0_IRQ 0x20000000
  141. #define B43_DMA64_DCTL0_FRAMEEND 0x40000000
  142. #define B43_DMA64_DCTL0_FRAMESTART 0x80000000
  143. #define B43_DMA64_DCTL1_BYTECNT 0x00001FFF
  144. #define B43_DMA64_DCTL1_ADDREXT_MASK 0x00030000
  145. #define B43_DMA64_DCTL1_ADDREXT_SHIFT 16
  146. struct b43_dmadesc_generic {
  147. union {
  148. struct b43_dmadesc32 dma32;
  149. struct b43_dmadesc64 dma64;
  150. } __packed;
  151. } __packed;
  152. /* Misc DMA constants */
  153. #define B43_DMA32_RINGMEMSIZE 4096
  154. #define B43_DMA64_RINGMEMSIZE 8192
  155. /* Offset of frame with actual data */
  156. #define B43_DMA0_RX_FW598_FO 38
  157. #define B43_DMA0_RX_FW351_FO 30
  158. /* DMA engine tuning knobs */
  159. #define B43_TXRING_SLOTS 256
  160. #define B43_RXRING_SLOTS 256
  161. #define B43_DMA0_RX_FW598_BUFSIZE (B43_DMA0_RX_FW598_FO + IEEE80211_MAX_FRAME_LEN)
  162. #define B43_DMA0_RX_FW351_BUFSIZE (B43_DMA0_RX_FW351_FO + IEEE80211_MAX_FRAME_LEN)
  163. /* Pointer poison */
  164. #define B43_DMA_PTR_POISON ((void *)ERR_PTR(-ENOMEM))
  165. #define b43_dma_ptr_is_poisoned(ptr) (unlikely((ptr) == B43_DMA_PTR_POISON))
  166. struct sk_buff;
  167. struct b43_private;
  168. struct b43_txstatus;
  169. struct b43_dmadesc_meta {
  170. /* The kernel DMA-able buffer. */
  171. struct sk_buff *skb;
  172. /* DMA base bus-address of the descriptor buffer. */
  173. dma_addr_t dmaaddr;
  174. /* ieee80211 TX status. Only used once per 802.11 frag. */
  175. bool is_last_fragment;
  176. };
  177. struct b43_dmaring;
  178. /* Lowlevel DMA operations that differ between 32bit and 64bit DMA. */
  179. struct b43_dma_ops {
  180. struct b43_dmadesc_generic *(*idx2desc) (struct b43_dmaring * ring,
  181. int slot,
  182. struct b43_dmadesc_meta **
  183. meta);
  184. void (*fill_descriptor) (struct b43_dmaring * ring,
  185. struct b43_dmadesc_generic * desc,
  186. dma_addr_t dmaaddr, u16 bufsize, int start,
  187. int end, int irq);
  188. void (*poke_tx) (struct b43_dmaring * ring, int slot);
  189. void (*tx_suspend) (struct b43_dmaring * ring);
  190. void (*tx_resume) (struct b43_dmaring * ring);
  191. int (*get_current_rxslot) (struct b43_dmaring * ring);
  192. void (*set_current_rxslot) (struct b43_dmaring * ring, int slot);
  193. };
  194. enum b43_dmatype {
  195. B43_DMA_30BIT = 30,
  196. B43_DMA_32BIT = 32,
  197. B43_DMA_64BIT = 64,
  198. };
  199. enum b43_addrtype {
  200. B43_DMA_ADDR_LOW,
  201. B43_DMA_ADDR_HIGH,
  202. B43_DMA_ADDR_EXT,
  203. };
  204. struct b43_dmaring {
  205. /* Lowlevel DMA ops. */
  206. const struct b43_dma_ops *ops;
  207. /* Kernel virtual base address of the ring memory. */
  208. void *descbase;
  209. /* Meta data about all descriptors. */
  210. struct b43_dmadesc_meta *meta;
  211. /* Cache of TX headers for each TX frame.
  212. * This is to avoid an allocation on each TX.
  213. * This is NULL for an RX ring.
  214. */
  215. u8 *txhdr_cache;
  216. /* (Unadjusted) DMA base bus-address of the ring memory. */
  217. dma_addr_t dmabase;
  218. /* Number of descriptor slots in the ring. */
  219. int nr_slots;
  220. /* Number of used descriptor slots. */
  221. int used_slots;
  222. /* Currently used slot in the ring. */
  223. int current_slot;
  224. /* Frameoffset in octets. */
  225. u32 frameoffset;
  226. /* Descriptor buffer size. */
  227. u16 rx_buffersize;
  228. /* The MMIO base register of the DMA controller. */
  229. u16 mmio_base;
  230. /* DMA controller index number (0-5). */
  231. int index;
  232. /* Boolean. Is this a TX ring? */
  233. bool tx;
  234. /* The type of DMA engine used. */
  235. enum b43_dmatype type;
  236. /* Boolean. Is this ring stopped at ieee80211 level? */
  237. bool stopped;
  238. /* The QOS priority assigned to this ring. Only used for TX rings.
  239. * This is the mac80211 "queue" value. */
  240. u8 queue_prio;
  241. struct b43_wldev *dev;
  242. #ifdef CONFIG_B43_DEBUG
  243. /* Maximum number of used slots. */
  244. int max_used_slots;
  245. /* Last time we injected a ring overflow. */
  246. unsigned long last_injected_overflow;
  247. /* Statistics: Number of successfully transmitted packets */
  248. u64 nr_succeed_tx_packets;
  249. /* Statistics: Number of failed TX packets */
  250. u64 nr_failed_tx_packets;
  251. /* Statistics: Total number of TX plus all retries. */
  252. u64 nr_total_packet_tries;
  253. #endif /* CONFIG_B43_DEBUG */
  254. };
  255. static inline u32 b43_dma_read(struct b43_dmaring *ring, u16 offset)
  256. {
  257. return b43_read32(ring->dev, ring->mmio_base + offset);
  258. }
  259. static inline void b43_dma_write(struct b43_dmaring *ring, u16 offset, u32 value)
  260. {
  261. b43_write32(ring->dev, ring->mmio_base + offset, value);
  262. }
  263. int b43_dma_init(struct b43_wldev *dev);
  264. void b43_dma_free(struct b43_wldev *dev);
  265. void b43_dma_tx_suspend(struct b43_wldev *dev);
  266. void b43_dma_tx_resume(struct b43_wldev *dev);
  267. int b43_dma_tx(struct b43_wldev *dev,
  268. struct sk_buff *skb);
  269. void b43_dma_handle_txstatus(struct b43_wldev *dev,
  270. const struct b43_txstatus *status);
  271. void b43_dma_handle_rx_overflow(struct b43_dmaring *ring);
  272. void b43_dma_rx(struct b43_dmaring *ring);
  273. void b43_dma_direct_fifo_rx(struct b43_wldev *dev,
  274. unsigned int engine_index, bool enable);
  275. #endif /* B43_DMA_H_ */