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