dma.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 <asm/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. } __attribute__((__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. /*** 64-bit DMA Engine. ***/
  76. /* 64-bit DMA controller registers. */
  77. #define B43legacy_DMA64_TXCTL 0x00
  78. #define B43legacy_DMA64_TXENABLE 0x00000001
  79. #define B43legacy_DMA64_TXSUSPEND 0x00000002
  80. #define B43legacy_DMA64_TXLOOPBACK 0x00000004
  81. #define B43legacy_DMA64_TXFLUSH 0x00000010
  82. #define B43legacy_DMA64_TXADDREXT_MASK 0x00030000
  83. #define B43legacy_DMA64_TXADDREXT_SHIFT 16
  84. #define B43legacy_DMA64_TXINDEX 0x04
  85. #define B43legacy_DMA64_TXRINGLO 0x08
  86. #define B43legacy_DMA64_TXRINGHI 0x0C
  87. #define B43legacy_DMA64_TXSTATUS 0x10
  88. #define B43legacy_DMA64_TXSTATDPTR 0x00001FFF
  89. #define B43legacy_DMA64_TXSTAT 0xF0000000
  90. #define B43legacy_DMA64_TXSTAT_DISABLED 0x00000000
  91. #define B43legacy_DMA64_TXSTAT_ACTIVE 0x10000000
  92. #define B43legacy_DMA64_TXSTAT_IDLEWAIT 0x20000000
  93. #define B43legacy_DMA64_TXSTAT_STOPPED 0x30000000
  94. #define B43legacy_DMA64_TXSTAT_SUSP 0x40000000
  95. #define B43legacy_DMA64_TXERROR 0x14
  96. #define B43legacy_DMA64_TXERRDPTR 0x0001FFFF
  97. #define B43legacy_DMA64_TXERR 0xF0000000
  98. #define B43legacy_DMA64_TXERR_NOERR 0x00000000
  99. #define B43legacy_DMA64_TXERR_PROT 0x10000000
  100. #define B43legacy_DMA64_TXERR_UNDERRUN 0x20000000
  101. #define B43legacy_DMA64_TXERR_TRANSFER 0x30000000
  102. #define B43legacy_DMA64_TXERR_DESCREAD 0x40000000
  103. #define B43legacy_DMA64_TXERR_CORE 0x50000000
  104. #define B43legacy_DMA64_RXCTL 0x20
  105. #define B43legacy_DMA64_RXENABLE 0x00000001
  106. #define B43legacy_DMA64_RXFROFF_MASK 0x000000FE
  107. #define B43legacy_DMA64_RXFROFF_SHIFT 1
  108. #define B43legacy_DMA64_RXDIRECTFIFO 0x00000100
  109. #define B43legacy_DMA64_RXADDREXT_MASK 0x00030000
  110. #define B43legacy_DMA64_RXADDREXT_SHIFT 16
  111. #define B43legacy_DMA64_RXINDEX 0x24
  112. #define B43legacy_DMA64_RXRINGLO 0x28
  113. #define B43legacy_DMA64_RXRINGHI 0x2C
  114. #define B43legacy_DMA64_RXSTATUS 0x30
  115. #define B43legacy_DMA64_RXSTATDPTR 0x00001FFF
  116. #define B43legacy_DMA64_RXSTAT 0xF0000000
  117. #define B43legacy_DMA64_RXSTAT_DISABLED 0x00000000
  118. #define B43legacy_DMA64_RXSTAT_ACTIVE 0x10000000
  119. #define B43legacy_DMA64_RXSTAT_IDLEWAIT 0x20000000
  120. #define B43legacy_DMA64_RXSTAT_STOPPED 0x30000000
  121. #define B43legacy_DMA64_RXSTAT_SUSP 0x40000000
  122. #define B43legacy_DMA64_RXERROR 0x34
  123. #define B43legacy_DMA64_RXERRDPTR 0x0001FFFF
  124. #define B43legacy_DMA64_RXERR 0xF0000000
  125. #define B43legacy_DMA64_RXERR_NOERR 0x00000000
  126. #define B43legacy_DMA64_RXERR_PROT 0x10000000
  127. #define B43legacy_DMA64_RXERR_UNDERRUN 0x20000000
  128. #define B43legacy_DMA64_RXERR_TRANSFER 0x30000000
  129. #define B43legacy_DMA64_RXERR_DESCREAD 0x40000000
  130. #define B43legacy_DMA64_RXERR_CORE 0x50000000
  131. /* 64-bit DMA descriptor. */
  132. struct b43legacy_dmadesc64 {
  133. __le32 control0;
  134. __le32 control1;
  135. __le32 address_low;
  136. __le32 address_high;
  137. } __attribute__((__packed__));
  138. #define B43legacy_DMA64_DCTL0_DTABLEEND 0x10000000
  139. #define B43legacy_DMA64_DCTL0_IRQ 0x20000000
  140. #define B43legacy_DMA64_DCTL0_FRAMEEND 0x40000000
  141. #define B43legacy_DMA64_DCTL0_FRAMESTART 0x80000000
  142. #define B43legacy_DMA64_DCTL1_BYTECNT 0x00001FFF
  143. #define B43legacy_DMA64_DCTL1_ADDREXT_MASK 0x00030000
  144. #define B43legacy_DMA64_DCTL1_ADDREXT_SHIFT 16
  145. struct b43legacy_dmadesc_generic {
  146. union {
  147. struct b43legacy_dmadesc32 dma32;
  148. struct b43legacy_dmadesc64 dma64;
  149. } __attribute__((__packed__));
  150. } __attribute__((__packed__));
  151. /* Misc DMA constants */
  152. #define B43legacy_DMA_RINGMEMSIZE PAGE_SIZE
  153. #define B43legacy_DMA0_RX_FRAMEOFFSET 30
  154. #define B43legacy_DMA3_RX_FRAMEOFFSET 0
  155. /* DMA engine tuning knobs */
  156. #define B43legacy_TXRING_SLOTS 128
  157. #define B43legacy_RXRING_SLOTS 64
  158. #define B43legacy_DMA0_RX_BUFFERSIZE (2304 + 100)
  159. #define B43legacy_DMA3_RX_BUFFERSIZE 16
  160. #ifdef CONFIG_B43LEGACY_DMA
  161. struct sk_buff;
  162. struct b43legacy_private;
  163. struct b43legacy_txstatus;
  164. struct b43legacy_dmadesc_meta {
  165. /* The kernel DMA-able buffer. */
  166. struct sk_buff *skb;
  167. /* DMA base bus-address of the descriptor buffer. */
  168. dma_addr_t dmaaddr;
  169. /* ieee80211 TX status. Only used once per 802.11 frag. */
  170. bool is_last_fragment;
  171. struct ieee80211_tx_status txstat;
  172. };
  173. struct b43legacy_dmaring;
  174. /* Lowlevel DMA operations that differ between 32bit and 64bit DMA. */
  175. struct b43legacy_dma_ops {
  176. struct b43legacy_dmadesc_generic * (*idx2desc)
  177. (struct b43legacy_dmaring *ring,
  178. int slot,
  179. struct b43legacy_dmadesc_meta
  180. **meta);
  181. void (*fill_descriptor)(struct b43legacy_dmaring *ring,
  182. struct b43legacy_dmadesc_generic *desc,
  183. dma_addr_t dmaaddr, u16 bufsize,
  184. int start, int end, int irq);
  185. void (*poke_tx)(struct b43legacy_dmaring *ring, int slot);
  186. void (*tx_suspend)(struct b43legacy_dmaring *ring);
  187. void (*tx_resume)(struct b43legacy_dmaring *ring);
  188. int (*get_current_rxslot)(struct b43legacy_dmaring *ring);
  189. void (*set_current_rxslot)(struct b43legacy_dmaring *ring, int slot);
  190. };
  191. struct b43legacy_dmaring {
  192. /* Lowlevel DMA ops. */
  193. const struct b43legacy_dma_ops *ops;
  194. /* Kernel virtual base address of the ring memory. */
  195. void *descbase;
  196. /* Meta data about all descriptors. */
  197. struct b43legacy_dmadesc_meta *meta;
  198. /* Cache of TX headers for each slot.
  199. * This is to avoid an allocation on each TX.
  200. * This is NULL for an RX ring.
  201. */
  202. u8 *txhdr_cache;
  203. /* (Unadjusted) DMA base bus-address of the ring memory. */
  204. dma_addr_t dmabase;
  205. /* Number of descriptor slots in the ring. */
  206. int nr_slots;
  207. /* Number of used descriptor slots. */
  208. int used_slots;
  209. /* Currently used slot in the ring. */
  210. int current_slot;
  211. /* Total number of packets sent. Statistics only. */
  212. unsigned int nr_tx_packets;
  213. /* Frameoffset in octets. */
  214. u32 frameoffset;
  215. /* Descriptor buffer size. */
  216. u16 rx_buffersize;
  217. /* The MMIO base register of the DMA controller. */
  218. u16 mmio_base;
  219. /* DMA controller index number (0-5). */
  220. int index;
  221. /* Boolean. Is this a TX ring? */
  222. bool tx;
  223. /* Boolean. 64bit DMA if true, 32bit DMA otherwise. */
  224. bool dma64;
  225. /* Boolean. Is this ring stopped at ieee80211 level? */
  226. bool stopped;
  227. /* Lock, only used for TX. */
  228. spinlock_t lock;
  229. struct b43legacy_wldev *dev;
  230. #ifdef CONFIG_B43LEGACY_DEBUG
  231. /* Maximum number of used slots. */
  232. int max_used_slots;
  233. /* Last time we injected a ring overflow. */
  234. unsigned long last_injected_overflow;
  235. #endif /* CONFIG_B43LEGACY_DEBUG*/
  236. };
  237. static inline
  238. u32 b43legacy_dma_read(struct b43legacy_dmaring *ring,
  239. u16 offset)
  240. {
  241. return b43legacy_read32(ring->dev, ring->mmio_base + offset);
  242. }
  243. static inline
  244. void b43legacy_dma_write(struct b43legacy_dmaring *ring,
  245. u16 offset, u32 value)
  246. {
  247. b43legacy_write32(ring->dev, ring->mmio_base + offset, value);
  248. }
  249. int b43legacy_dma_init(struct b43legacy_wldev *dev);
  250. void b43legacy_dma_free(struct b43legacy_wldev *dev);
  251. int b43legacy_dmacontroller_rx_reset(struct b43legacy_wldev *dev,
  252. u16 dmacontroller_mmio_base,
  253. int dma64);
  254. int b43legacy_dmacontroller_tx_reset(struct b43legacy_wldev *dev,
  255. u16 dmacontroller_mmio_base,
  256. int dma64);
  257. u16 b43legacy_dmacontroller_base(int dma64bit, int dmacontroller_idx);
  258. void b43legacy_dma_tx_suspend(struct b43legacy_wldev *dev);
  259. void b43legacy_dma_tx_resume(struct b43legacy_wldev *dev);
  260. void b43legacy_dma_get_tx_stats(struct b43legacy_wldev *dev,
  261. struct ieee80211_tx_queue_stats *stats);
  262. int b43legacy_dma_tx(struct b43legacy_wldev *dev,
  263. struct sk_buff *skb,
  264. struct ieee80211_tx_control *ctl);
  265. void b43legacy_dma_handle_txstatus(struct b43legacy_wldev *dev,
  266. const struct b43legacy_txstatus *status);
  267. void b43legacy_dma_rx(struct b43legacy_dmaring *ring);
  268. #else /* CONFIG_B43LEGACY_DMA */
  269. static inline
  270. int b43legacy_dma_init(struct b43legacy_wldev *dev)
  271. {
  272. return 0;
  273. }
  274. static inline
  275. void b43legacy_dma_free(struct b43legacy_wldev *dev)
  276. {
  277. }
  278. static inline
  279. int b43legacy_dmacontroller_rx_reset(struct b43legacy_wldev *dev,
  280. u16 dmacontroller_mmio_base,
  281. int dma64)
  282. {
  283. return 0;
  284. }
  285. static inline
  286. int b43legacy_dmacontroller_tx_reset(struct b43legacy_wldev *dev,
  287. u16 dmacontroller_mmio_base,
  288. int dma64)
  289. {
  290. return 0;
  291. }
  292. static inline
  293. void b43legacy_dma_get_tx_stats(struct b43legacy_wldev *dev,
  294. struct ieee80211_tx_queue_stats *stats)
  295. {
  296. }
  297. static inline
  298. int b43legacy_dma_tx(struct b43legacy_wldev *dev,
  299. struct sk_buff *skb,
  300. struct ieee80211_tx_control *ctl)
  301. {
  302. return 0;
  303. }
  304. static inline
  305. void b43legacy_dma_handle_txstatus(struct b43legacy_wldev *dev,
  306. const struct b43legacy_txstatus *status)
  307. {
  308. }
  309. static inline
  310. void b43legacy_dma_rx(struct b43legacy_dmaring *ring)
  311. {
  312. }
  313. static inline
  314. void b43legacy_dma_tx_suspend(struct b43legacy_wldev *dev)
  315. {
  316. }
  317. static inline
  318. void b43legacy_dma_tx_resume(struct b43legacy_wldev *dev)
  319. {
  320. }
  321. #endif /* CONFIG_B43LEGACY_DMA */
  322. #endif /* B43legacy_DMA_H_ */