John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Broadcom BCM43xx wireless driver |
| 4 | |
| 5 | PIO Transmission |
| 6 | |
| 7 | Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de> |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; see the file COPYING. If not, write to |
| 21 | the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, |
| 22 | Boston, MA 02110-1301, USA. |
| 23 | |
| 24 | */ |
| 25 | |
| 26 | #include "bcm43xx.h" |
| 27 | #include "bcm43xx_pio.h" |
| 28 | #include "bcm43xx_main.h" |
Michael Buesch | f398f02 | 2006-02-23 21:15:39 +0100 | [diff] [blame] | 29 | #include "bcm43xx_xmit.h" |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 30 | |
| 31 | #include <linux/delay.h> |
| 32 | |
| 33 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 34 | static void tx_start(struct bcm43xx_pioqueue *queue) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 35 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 36 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL, |
| 37 | BCM43xx_PIO_TXCTL_INIT); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 38 | } |
| 39 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 40 | static void tx_octet(struct bcm43xx_pioqueue *queue, |
| 41 | u8 octet) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 42 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 43 | if (queue->need_workarounds) { |
| 44 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, |
| 45 | octet); |
| 46 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL, |
| 47 | BCM43xx_PIO_TXCTL_WRITEHI); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 48 | } else { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 49 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL, |
| 50 | BCM43xx_PIO_TXCTL_WRITEHI); |
| 51 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, |
| 52 | octet); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 56 | static u16 tx_get_next_word(struct bcm43xx_txhdr *txhdr, |
| 57 | const u8 *packet, |
| 58 | unsigned int *pos) |
| 59 | { |
| 60 | const u8 *source; |
| 61 | unsigned int i = *pos; |
| 62 | u16 ret; |
| 63 | |
| 64 | if (i < sizeof(*txhdr)) { |
| 65 | source = (const u8 *)txhdr; |
| 66 | } else { |
| 67 | source = packet; |
| 68 | i -= sizeof(*txhdr); |
| 69 | } |
| 70 | ret = le16_to_cpu( *((u16 *)(source + i)) ); |
| 71 | *pos += 2; |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static void tx_data(struct bcm43xx_pioqueue *queue, |
| 77 | struct bcm43xx_txhdr *txhdr, |
| 78 | const u8 *packet, |
| 79 | unsigned int octets) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 80 | { |
| 81 | u16 data; |
| 82 | unsigned int i = 0; |
| 83 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 84 | if (queue->need_workarounds) { |
| 85 | data = tx_get_next_word(txhdr, packet, &i); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 86 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 87 | } |
| 88 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL, |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 89 | BCM43xx_PIO_TXCTL_WRITELO | |
| 90 | BCM43xx_PIO_TXCTL_WRITEHI); |
| 91 | while (i < octets - 1) { |
| 92 | data = tx_get_next_word(txhdr, packet, &i); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 93 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data); |
| 94 | } |
| 95 | if (octets % 2) |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 96 | tx_octet(queue, packet[octets - sizeof(*txhdr) - 1]); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 99 | static void tx_complete(struct bcm43xx_pioqueue *queue, |
| 100 | struct sk_buff *skb) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 101 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 102 | if (queue->need_workarounds) { |
| 103 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, |
| 104 | skb->data[skb->len - 1]); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 105 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL, |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 106 | BCM43xx_PIO_TXCTL_WRITEHI | |
| 107 | BCM43xx_PIO_TXCTL_COMPLETE); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 108 | } else { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 109 | bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL, |
| 110 | BCM43xx_PIO_TXCTL_COMPLETE); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 114 | static u16 generate_cookie(struct bcm43xx_pioqueue *queue, |
| 115 | int packetindex) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 116 | { |
| 117 | u16 cookie = 0x0000; |
| 118 | |
| 119 | /* We use the upper 4 bits for the PIO |
| 120 | * controller ID and the lower 12 bits |
| 121 | * for the packet index (in the cache). |
| 122 | */ |
| 123 | switch (queue->mmio_base) { |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 124 | case BCM43xx_MMIO_PIO1_BASE: |
| 125 | break; |
| 126 | case BCM43xx_MMIO_PIO2_BASE: |
| 127 | cookie = 0x1000; |
| 128 | break; |
| 129 | case BCM43xx_MMIO_PIO3_BASE: |
| 130 | cookie = 0x2000; |
| 131 | break; |
| 132 | case BCM43xx_MMIO_PIO4_BASE: |
| 133 | cookie = 0x3000; |
| 134 | break; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 135 | default: |
| 136 | assert(0); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 137 | } |
| 138 | assert(((u16)packetindex & 0xF000) == 0x0000); |
| 139 | cookie |= (u16)packetindex; |
| 140 | |
| 141 | return cookie; |
| 142 | } |
| 143 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 144 | static |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 145 | struct bcm43xx_pioqueue * parse_cookie(struct bcm43xx_private *bcm, |
| 146 | u16 cookie, |
| 147 | struct bcm43xx_pio_txpacket **packet) |
| 148 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 149 | struct bcm43xx_pio *pio = bcm->current_core->pio; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 150 | struct bcm43xx_pioqueue *queue = NULL; |
| 151 | int packetindex; |
| 152 | |
| 153 | switch (cookie & 0xF000) { |
| 154 | case 0x0000: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 155 | queue = pio->queue0; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 156 | break; |
| 157 | case 0x1000: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 158 | queue = pio->queue1; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 159 | break; |
| 160 | case 0x2000: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 161 | queue = pio->queue2; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 162 | break; |
| 163 | case 0x3000: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 164 | queue = pio->queue3; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 165 | break; |
| 166 | default: |
| 167 | assert(0); |
| 168 | } |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 169 | packetindex = (cookie & 0x0FFF); |
| 170 | assert(packetindex >= 0 && packetindex < BCM43xx_PIO_MAXTXPACKETS); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 171 | *packet = &(queue->tx_packets_cache[packetindex]); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 172 | |
| 173 | return queue; |
| 174 | } |
| 175 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 176 | static void pio_tx_write_fragment(struct bcm43xx_pioqueue *queue, |
| 177 | struct sk_buff *skb, |
| 178 | struct bcm43xx_pio_txpacket *packet) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 179 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 180 | struct bcm43xx_txhdr txhdr; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 181 | unsigned int octets; |
| 182 | |
| 183 | assert(skb_shinfo(skb)->nr_frags == 0); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 184 | bcm43xx_generate_txhdr(queue->bcm, |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 185 | &txhdr, skb->data, skb->len, |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 186 | (packet->xmitted_frags == 0), |
| 187 | generate_cookie(queue, pio_txpacket_getindex(packet))); |
| 188 | |
| 189 | tx_start(queue); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 190 | octets = skb->len + sizeof(txhdr); |
| 191 | if (queue->need_workarounds) |
| 192 | octets--; |
| 193 | tx_data(queue, &txhdr, (u8 *)skb->data, octets); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 194 | tx_complete(queue, skb); |
| 195 | } |
| 196 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 197 | static void free_txpacket(struct bcm43xx_pio_txpacket *packet, |
| 198 | int irq_context) |
| 199 | { |
| 200 | struct bcm43xx_pioqueue *queue = packet->queue; |
| 201 | |
| 202 | ieee80211_txb_free(packet->txb); |
| 203 | list_move(&packet->list, &queue->txfree); |
| 204 | queue->nr_txfree++; |
| 205 | |
| 206 | assert(queue->tx_devq_used >= packet->xmitted_octets); |
| 207 | assert(queue->tx_devq_packets >= packet->xmitted_frags); |
| 208 | queue->tx_devq_used -= packet->xmitted_octets; |
| 209 | queue->tx_devq_packets -= packet->xmitted_frags; |
| 210 | } |
| 211 | |
| 212 | static int pio_tx_packet(struct bcm43xx_pio_txpacket *packet) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 213 | { |
| 214 | struct bcm43xx_pioqueue *queue = packet->queue; |
| 215 | struct ieee80211_txb *txb = packet->txb; |
| 216 | struct sk_buff *skb; |
| 217 | u16 octets; |
| 218 | int i; |
| 219 | |
| 220 | for (i = packet->xmitted_frags; i < txb->nr_frags; i++) { |
| 221 | skb = txb->fragments[i]; |
| 222 | |
| 223 | octets = (u16)skb->len + sizeof(struct bcm43xx_txhdr); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 224 | assert(queue->tx_devq_size >= octets); |
| 225 | assert(queue->tx_devq_packets <= BCM43xx_PIO_MAXTXDEVQPACKETS); |
| 226 | assert(queue->tx_devq_used <= queue->tx_devq_size); |
| 227 | /* Check if there is sufficient free space on the device |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 228 | * TX queue. If not, return and let the TX tasklet |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 229 | * retry later. |
| 230 | */ |
| 231 | if (queue->tx_devq_packets == BCM43xx_PIO_MAXTXDEVQPACKETS) |
| 232 | return -EBUSY; |
| 233 | if (queue->tx_devq_used + octets > queue->tx_devq_size) |
| 234 | return -EBUSY; |
| 235 | /* Now poke the device. */ |
| 236 | pio_tx_write_fragment(queue, skb, packet); |
| 237 | |
| 238 | /* Account for the packet size. |
| 239 | * (We must not overflow the device TX queue) |
| 240 | */ |
| 241 | queue->tx_devq_packets++; |
| 242 | queue->tx_devq_used += octets; |
| 243 | |
| 244 | assert(packet->xmitted_frags <= packet->txb->nr_frags); |
| 245 | packet->xmitted_frags++; |
| 246 | packet->xmitted_octets += octets; |
| 247 | } |
| 248 | list_move_tail(&packet->list, &queue->txrunning); |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 253 | static void tx_tasklet(unsigned long d) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 254 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 255 | struct bcm43xx_pioqueue *queue = (struct bcm43xx_pioqueue *)d; |
| 256 | struct bcm43xx_private *bcm = queue->bcm; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 257 | unsigned long flags; |
| 258 | struct bcm43xx_pio_txpacket *packet, *tmp_packet; |
| 259 | int err; |
| 260 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 261 | spin_lock_irqsave(&bcm->lock, flags); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 262 | list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) { |
| 263 | assert(packet->xmitted_frags < packet->txb->nr_frags); |
| 264 | if (packet->xmitted_frags == 0) { |
| 265 | int i; |
| 266 | struct sk_buff *skb; |
| 267 | |
| 268 | /* Check if the device queue is big |
| 269 | * enough for every fragment. If not, drop the |
| 270 | * whole packet. |
| 271 | */ |
| 272 | for (i = 0; i < packet->txb->nr_frags; i++) { |
| 273 | skb = packet->txb->fragments[i]; |
| 274 | if (unlikely(skb->len > queue->tx_devq_size)) { |
| 275 | dprintkl(KERN_ERR PFX "PIO TX device queue too small. " |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 276 | "Dropping packet.\n"); |
| 277 | free_txpacket(packet, 1); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 278 | goto next_packet; |
| 279 | } |
| 280 | } |
| 281 | } |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 282 | /* Try to transmit the packet. |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 283 | * This may not completely succeed. |
| 284 | */ |
| 285 | err = pio_tx_packet(packet); |
| 286 | if (err) |
| 287 | break; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 288 | next_packet: |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 289 | continue; |
| 290 | } |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 291 | spin_unlock_irqrestore(&bcm->lock, flags); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void setup_txqueues(struct bcm43xx_pioqueue *queue) |
| 295 | { |
| 296 | struct bcm43xx_pio_txpacket *packet; |
| 297 | int i; |
| 298 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 299 | queue->nr_txfree = BCM43xx_PIO_MAXTXPACKETS; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 300 | for (i = 0; i < BCM43xx_PIO_MAXTXPACKETS; i++) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 301 | packet = &(queue->tx_packets_cache[i]); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 302 | |
| 303 | packet->queue = queue; |
| 304 | INIT_LIST_HEAD(&packet->list); |
| 305 | |
| 306 | list_add(&packet->list, &queue->txfree); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | static |
| 311 | struct bcm43xx_pioqueue * bcm43xx_setup_pioqueue(struct bcm43xx_private *bcm, |
| 312 | u16 pio_mmio_base) |
| 313 | { |
| 314 | struct bcm43xx_pioqueue *queue; |
| 315 | u32 value; |
| 316 | u16 qsize; |
| 317 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 318 | queue = kzalloc(sizeof(*queue), GFP_KERNEL); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 319 | if (!queue) |
| 320 | goto out; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 321 | |
| 322 | queue->bcm = bcm; |
| 323 | queue->mmio_base = pio_mmio_base; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 324 | queue->need_workarounds = (bcm->current_core->rev < 3); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 325 | |
| 326 | INIT_LIST_HEAD(&queue->txfree); |
| 327 | INIT_LIST_HEAD(&queue->txqueue); |
| 328 | INIT_LIST_HEAD(&queue->txrunning); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 329 | tasklet_init(&queue->txtask, tx_tasklet, |
| 330 | (unsigned long)queue); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 331 | |
| 332 | value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); |
| 333 | value |= BCM43xx_SBF_XFER_REG_BYTESWAP; |
| 334 | bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value); |
| 335 | |
| 336 | qsize = bcm43xx_read16(bcm, queue->mmio_base + BCM43xx_PIO_TXQBUFSIZE); |
| 337 | if (qsize <= BCM43xx_PIO_TXQADJUST) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 338 | printk(KERN_ERR PFX "PIO tx device-queue too small (%u)\n", qsize); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 339 | goto err_freequeue; |
| 340 | } |
| 341 | qsize -= BCM43xx_PIO_TXQADJUST; |
| 342 | queue->tx_devq_size = qsize; |
| 343 | |
| 344 | setup_txqueues(queue); |
| 345 | |
| 346 | out: |
| 347 | return queue; |
| 348 | |
| 349 | err_freequeue: |
| 350 | kfree(queue); |
| 351 | queue = NULL; |
| 352 | goto out; |
| 353 | } |
| 354 | |
| 355 | static void cancel_transfers(struct bcm43xx_pioqueue *queue) |
| 356 | { |
| 357 | struct bcm43xx_pio_txpacket *packet, *tmp_packet; |
| 358 | |
| 359 | netif_tx_disable(queue->bcm->net_dev); |
| 360 | assert(queue->bcm->shutting_down); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 361 | tasklet_disable(&queue->txtask); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 362 | |
| 363 | list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list) |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 364 | free_txpacket(packet, 0); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 365 | list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 366 | free_txpacket(packet, 0); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static void bcm43xx_destroy_pioqueue(struct bcm43xx_pioqueue *queue) |
| 370 | { |
| 371 | if (!queue) |
| 372 | return; |
| 373 | |
| 374 | cancel_transfers(queue); |
| 375 | kfree(queue); |
| 376 | } |
| 377 | |
| 378 | void bcm43xx_pio_free(struct bcm43xx_private *bcm) |
| 379 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 380 | struct bcm43xx_pio *pio = bcm->current_core->pio; |
| 381 | |
| 382 | bcm43xx_destroy_pioqueue(pio->queue3); |
| 383 | pio->queue3 = NULL; |
| 384 | bcm43xx_destroy_pioqueue(pio->queue2); |
| 385 | pio->queue2 = NULL; |
| 386 | bcm43xx_destroy_pioqueue(pio->queue1); |
| 387 | pio->queue1 = NULL; |
| 388 | bcm43xx_destroy_pioqueue(pio->queue0); |
| 389 | pio->queue0 = NULL; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | int bcm43xx_pio_init(struct bcm43xx_private *bcm) |
| 393 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 394 | struct bcm43xx_pio *pio = bcm->current_core->pio; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 395 | struct bcm43xx_pioqueue *queue; |
| 396 | int err = -ENOMEM; |
| 397 | |
| 398 | queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO1_BASE); |
| 399 | if (!queue) |
| 400 | goto out; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 401 | pio->queue0 = queue; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 402 | |
| 403 | queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO2_BASE); |
| 404 | if (!queue) |
| 405 | goto err_destroy0; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 406 | pio->queue1 = queue; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 407 | |
| 408 | queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO3_BASE); |
| 409 | if (!queue) |
| 410 | goto err_destroy1; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 411 | pio->queue2 = queue; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 412 | |
| 413 | queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO4_BASE); |
| 414 | if (!queue) |
| 415 | goto err_destroy2; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 416 | pio->queue3 = queue; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 417 | |
| 418 | if (bcm->current_core->rev < 3) |
| 419 | bcm->irq_savedstate |= BCM43xx_IRQ_PIO_WORKAROUND; |
| 420 | |
| 421 | dprintk(KERN_INFO PFX "PIO initialized\n"); |
| 422 | err = 0; |
| 423 | out: |
| 424 | return err; |
| 425 | |
| 426 | err_destroy2: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 427 | bcm43xx_destroy_pioqueue(pio->queue2); |
| 428 | pio->queue2 = NULL; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 429 | err_destroy1: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 430 | bcm43xx_destroy_pioqueue(pio->queue1); |
| 431 | pio->queue1 = NULL; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 432 | err_destroy0: |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 433 | bcm43xx_destroy_pioqueue(pio->queue0); |
| 434 | pio->queue0 = NULL; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 435 | goto out; |
| 436 | } |
| 437 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 438 | int bcm43xx_pio_tx(struct bcm43xx_private *bcm, |
| 439 | struct ieee80211_txb *txb) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 440 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 441 | struct bcm43xx_pioqueue *queue = bcm->current_core->pio->queue1; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 442 | struct bcm43xx_pio_txpacket *packet; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 443 | u16 tmp; |
| 444 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 445 | assert(!queue->tx_suspended); |
| 446 | assert(!list_empty(&queue->txfree)); |
| 447 | |
| 448 | tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 449 | if (tmp & BCM43xx_PIO_TXCTL_SUSPEND) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 450 | return -EBUSY; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 451 | |
| 452 | packet = list_entry(queue->txfree.next, struct bcm43xx_pio_txpacket, list); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 453 | packet->txb = txb; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 454 | packet->xmitted_frags = 0; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 455 | packet->xmitted_octets = 0; |
| 456 | list_move_tail(&packet->list, &queue->txqueue); |
| 457 | queue->nr_txfree--; |
| 458 | assert(queue->nr_txfree < BCM43xx_PIO_MAXTXPACKETS); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 459 | |
| 460 | /* Suspend TX, if we are out of packets in the "free" queue. */ |
| 461 | if (unlikely(list_empty(&queue->txfree))) { |
| 462 | netif_stop_queue(queue->bcm->net_dev); |
| 463 | queue->tx_suspended = 1; |
| 464 | } |
| 465 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 466 | tasklet_schedule(&queue->txtask); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 471 | void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm, |
| 472 | struct bcm43xx_xmitstatus *status) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 473 | { |
| 474 | struct bcm43xx_pioqueue *queue; |
| 475 | struct bcm43xx_pio_txpacket *packet; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 476 | |
| 477 | queue = parse_cookie(bcm, status->cookie, &packet); |
| 478 | assert(queue); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 479 | //TODO |
| 480 | if (!queue) |
| 481 | return; |
| 482 | free_txpacket(packet, 1); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 483 | if (unlikely(queue->tx_suspended)) { |
| 484 | queue->tx_suspended = 0; |
| 485 | netif_wake_queue(queue->bcm->net_dev); |
| 486 | } |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 487 | /* If there are packets on the txqueue, poke the tasklet. */ |
| 488 | if (!list_empty(&queue->txqueue)) |
| 489 | tasklet_schedule(&queue->txtask); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static void pio_rx_error(struct bcm43xx_pioqueue *queue, |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 493 | int clear_buffers, |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 494 | const char *error) |
| 495 | { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 496 | int i; |
| 497 | |
| 498 | printkl("PIO RX error: %s\n", error); |
| 499 | bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL, |
| 500 | BCM43xx_PIO_RXCTL_READY); |
| 501 | if (clear_buffers) { |
| 502 | assert(queue->mmio_base == BCM43xx_MMIO_PIO1_BASE); |
| 503 | for (i = 0; i < 15; i++) { |
| 504 | /* Dummy read. */ |
| 505 | bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA); |
| 506 | } |
| 507 | } |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 508 | } |
| 509 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 510 | void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 511 | { |
| 512 | u16 preamble[21] = { 0 }; |
| 513 | struct bcm43xx_rxhdr *rxhdr; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 514 | u16 tmp, len, rxflags2; |
| 515 | int i, preamble_readwords; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 516 | struct sk_buff *skb; |
| 517 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 518 | return; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 519 | tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL); |
| 520 | if (!(tmp & BCM43xx_PIO_RXCTL_DATAAVAILABLE)) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 521 | dprintkl(KERN_ERR PFX "PIO RX: No data available\n");//TODO: remove this printk. |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 522 | return; |
| 523 | } |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 524 | bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL, |
| 525 | BCM43xx_PIO_RXCTL_DATAAVAILABLE); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 526 | |
| 527 | for (i = 0; i < 10; i++) { |
| 528 | tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL); |
| 529 | if (tmp & BCM43xx_PIO_RXCTL_READY) |
| 530 | goto data_ready; |
| 531 | udelay(10); |
| 532 | } |
| 533 | dprintkl(KERN_ERR PFX "PIO RX timed out\n"); |
| 534 | return; |
| 535 | data_ready: |
| 536 | |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 537 | //FIXME: endianess in this function. |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 538 | len = le16_to_cpu(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA)); |
| 539 | if (unlikely(len > 0x700)) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 540 | pio_rx_error(queue, 0, "len > 0x700"); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 541 | return; |
| 542 | } |
| 543 | if (unlikely(len == 0 && queue->mmio_base != BCM43xx_MMIO_PIO4_BASE)) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 544 | pio_rx_error(queue, 0, "len == 0"); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 545 | return; |
| 546 | } |
| 547 | preamble[0] = cpu_to_le16(len); |
| 548 | if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE) |
| 549 | preamble_readwords = 14 / sizeof(u16); |
| 550 | else |
| 551 | preamble_readwords = 18 / sizeof(u16); |
| 552 | for (i = 0; i < preamble_readwords; i++) { |
| 553 | tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 554 | preamble[i + 1] = cpu_to_be16(tmp);//FIXME? |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 555 | } |
| 556 | rxhdr = (struct bcm43xx_rxhdr *)preamble; |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 557 | rxflags2 = le16_to_cpu(rxhdr->flags2); |
| 558 | if (unlikely(rxflags2 & BCM43xx_RXHDR_FLAGS2_INVALIDFRAME)) { |
| 559 | pio_rx_error(queue, |
| 560 | (queue->mmio_base == BCM43xx_MMIO_PIO1_BASE), |
| 561 | "invalid frame"); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 562 | return; |
| 563 | } |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 564 | if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 565 | /* We received an xmit status. */ |
| 566 | struct bcm43xx_hwxmitstatus *hw; |
| 567 | struct bcm43xx_xmitstatus stat; |
| 568 | |
| 569 | hw = (struct bcm43xx_hwxmitstatus *)(preamble + 1); |
| 570 | stat.cookie = le16_to_cpu(hw->cookie); |
| 571 | stat.flags = hw->flags; |
| 572 | stat.cnt1 = hw->cnt1; |
| 573 | stat.cnt2 = hw->cnt2; |
| 574 | stat.seq = le16_to_cpu(hw->seq); |
| 575 | stat.unknown = le16_to_cpu(hw->unknown); |
| 576 | |
| 577 | bcm43xx_debugfs_log_txstat(queue->bcm, &stat); |
| 578 | bcm43xx_pio_handle_xmitstatus(queue->bcm, &stat); |
| 579 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 580 | return; |
| 581 | } |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 582 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 583 | skb = dev_alloc_skb(len); |
| 584 | if (unlikely(!skb)) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 585 | pio_rx_error(queue, 1, "OOM"); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 586 | return; |
| 587 | } |
| 588 | skb_put(skb, len); |
| 589 | for (i = 0; i < len - 1; i += 2) { |
| 590 | tmp = cpu_to_be16(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA)); |
| 591 | *((u16 *)(skb->data + i)) = tmp; |
| 592 | } |
| 593 | if (len % 2) { |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 594 | tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 595 | skb->data[len - 1] = (tmp & 0x00FF); |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 596 | if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME) |
| 597 | skb->data[0x20] = (tmp & 0xFF00) >> 8; |
| 598 | else |
| 599 | skb->data[0x1E] = (tmp & 0xFF00) >> 8; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 600 | } |
Michael Buesch | 77db31e | 2006-02-12 16:47:44 +0100 | [diff] [blame] | 601 | bcm43xx_rx(queue->bcm, skb, rxhdr); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* vim: set ts=8 sw=8 sts=8: */ |