| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 |  | 
|  | 3 | Broadcom B43legacy wireless driver | 
|  | 4 |  | 
|  | 5 | PIO Transmission | 
|  | 6 |  | 
|  | 7 | Copyright (c) 2005 Michael Buesch <mb@bu3sch.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 "b43legacy.h" | 
|  | 27 | #include "pio.h" | 
|  | 28 | #include "main.h" | 
|  | 29 | #include "xmit.h" | 
|  | 30 |  | 
|  | 31 | #include <linux/delay.h> | 
|  | 32 |  | 
|  | 33 |  | 
|  | 34 | static void tx_start(struct b43legacy_pioqueue *queue) | 
|  | 35 | { | 
|  | 36 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 37 | B43legacy_PIO_TXCTL_INIT); | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | static void tx_octet(struct b43legacy_pioqueue *queue, | 
|  | 41 | u8 octet) | 
|  | 42 | { | 
|  | 43 | if (queue->need_workarounds) { | 
|  | 44 | b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, octet); | 
|  | 45 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 46 | B43legacy_PIO_TXCTL_WRITELO); | 
|  | 47 | } else { | 
|  | 48 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 49 | B43legacy_PIO_TXCTL_WRITELO); | 
|  | 50 | b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, octet); | 
|  | 51 | } | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | static u16 tx_get_next_word(const u8 *txhdr, | 
|  | 55 | const u8 *packet, | 
|  | 56 | size_t txhdr_size, | 
|  | 57 | unsigned int *pos) | 
|  | 58 | { | 
|  | 59 | const u8 *source; | 
|  | 60 | unsigned int i = *pos; | 
|  | 61 | u16 ret; | 
|  | 62 |  | 
|  | 63 | if (i < txhdr_size) | 
|  | 64 | source = txhdr; | 
|  | 65 | else { | 
|  | 66 | source = packet; | 
|  | 67 | i -= txhdr_size; | 
|  | 68 | } | 
|  | 69 | ret = le16_to_cpu(*((__le16 *)(source + i))); | 
|  | 70 | *pos += 2; | 
|  | 71 |  | 
|  | 72 | return ret; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | static void tx_data(struct b43legacy_pioqueue *queue, | 
|  | 76 | u8 *txhdr, | 
|  | 77 | const u8 *packet, | 
|  | 78 | unsigned int octets) | 
|  | 79 | { | 
|  | 80 | u16 data; | 
|  | 81 | unsigned int i = 0; | 
|  | 82 |  | 
|  | 83 | if (queue->need_workarounds) { | 
|  | 84 | data = tx_get_next_word(txhdr, packet, | 
|  | 85 | sizeof(struct b43legacy_txhdr_fw3), &i); | 
|  | 86 | b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, data); | 
|  | 87 | } | 
|  | 88 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 89 | B43legacy_PIO_TXCTL_WRITELO | | 
|  | 90 | B43legacy_PIO_TXCTL_WRITEHI); | 
|  | 91 | while (i < octets - 1) { | 
|  | 92 | data = tx_get_next_word(txhdr, packet, | 
|  | 93 | sizeof(struct b43legacy_txhdr_fw3), &i); | 
|  | 94 | b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, data); | 
|  | 95 | } | 
|  | 96 | if (octets % 2) | 
|  | 97 | tx_octet(queue, packet[octets - | 
|  | 98 | sizeof(struct b43legacy_txhdr_fw3) - 1]); | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | static void tx_complete(struct b43legacy_pioqueue *queue, | 
|  | 102 | struct sk_buff *skb) | 
|  | 103 | { | 
|  | 104 | if (queue->need_workarounds) { | 
|  | 105 | b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, | 
|  | 106 | skb->data[skb->len - 1]); | 
|  | 107 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 108 | B43legacy_PIO_TXCTL_WRITELO | | 
|  | 109 | B43legacy_PIO_TXCTL_COMPLETE); | 
|  | 110 | } else | 
|  | 111 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 112 | B43legacy_PIO_TXCTL_COMPLETE); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | static u16 generate_cookie(struct b43legacy_pioqueue *queue, | 
|  | 116 | struct b43legacy_pio_txpacket *packet) | 
|  | 117 | { | 
|  | 118 | u16 cookie = 0x0000; | 
|  | 119 | int packetindex; | 
|  | 120 |  | 
|  | 121 | /* We use the upper 4 bits for the PIO | 
|  | 122 | * controller ID and the lower 12 bits | 
|  | 123 | * for the packet index (in the cache). | 
|  | 124 | */ | 
|  | 125 | switch (queue->mmio_base) { | 
|  | 126 | case B43legacy_MMIO_PIO1_BASE: | 
|  | 127 | break; | 
|  | 128 | case B43legacy_MMIO_PIO2_BASE: | 
|  | 129 | cookie = 0x1000; | 
|  | 130 | break; | 
|  | 131 | case B43legacy_MMIO_PIO3_BASE: | 
|  | 132 | cookie = 0x2000; | 
|  | 133 | break; | 
|  | 134 | case B43legacy_MMIO_PIO4_BASE: | 
|  | 135 | cookie = 0x3000; | 
|  | 136 | break; | 
|  | 137 | default: | 
|  | 138 | B43legacy_WARN_ON(1); | 
|  | 139 | } | 
|  | 140 | packetindex = pio_txpacket_getindex(packet); | 
|  | 141 | B43legacy_WARN_ON(!(((u16)packetindex & 0xF000) == 0x0000)); | 
|  | 142 | cookie |= (u16)packetindex; | 
|  | 143 |  | 
|  | 144 | return cookie; | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | static | 
|  | 148 | struct b43legacy_pioqueue *parse_cookie(struct b43legacy_wldev *dev, | 
|  | 149 | u16 cookie, | 
|  | 150 | struct b43legacy_pio_txpacket **packet) | 
|  | 151 | { | 
|  | 152 | struct b43legacy_pio *pio = &dev->pio; | 
|  | 153 | struct b43legacy_pioqueue *queue = NULL; | 
|  | 154 | int packetindex; | 
|  | 155 |  | 
|  | 156 | switch (cookie & 0xF000) { | 
|  | 157 | case 0x0000: | 
|  | 158 | queue = pio->queue0; | 
|  | 159 | break; | 
|  | 160 | case 0x1000: | 
|  | 161 | queue = pio->queue1; | 
|  | 162 | break; | 
|  | 163 | case 0x2000: | 
|  | 164 | queue = pio->queue2; | 
|  | 165 | break; | 
|  | 166 | case 0x3000: | 
|  | 167 | queue = pio->queue3; | 
|  | 168 | break; | 
|  | 169 | default: | 
|  | 170 | B43legacy_WARN_ON(1); | 
|  | 171 | } | 
|  | 172 | packetindex = (cookie & 0x0FFF); | 
|  | 173 | B43legacy_WARN_ON(!(packetindex >= 0 && packetindex | 
|  | 174 | < B43legacy_PIO_MAXTXPACKETS)); | 
|  | 175 | *packet = &(queue->tx_packets_cache[packetindex]); | 
|  | 176 |  | 
|  | 177 | return queue; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | union txhdr_union { | 
|  | 181 | struct b43legacy_txhdr_fw3 txhdr_fw3; | 
|  | 182 | }; | 
|  | 183 |  | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 184 | static int pio_tx_write_fragment(struct b43legacy_pioqueue *queue, | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 185 | struct sk_buff *skb, | 
|  | 186 | struct b43legacy_pio_txpacket *packet, | 
|  | 187 | size_t txhdr_size) | 
|  | 188 | { | 
|  | 189 | union txhdr_union txhdr_data; | 
|  | 190 | u8 *txhdr = NULL; | 
|  | 191 | unsigned int octets; | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 192 | int err; | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 193 |  | 
|  | 194 | txhdr = (u8 *)(&txhdr_data.txhdr_fw3); | 
|  | 195 |  | 
|  | 196 | B43legacy_WARN_ON(skb_shinfo(skb)->nr_frags != 0); | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 197 | err = b43legacy_generate_txhdr(queue->dev, | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 198 | txhdr, skb->data, skb->len, | 
|  | 199 | &packet->txstat.control, | 
|  | 200 | generate_cookie(queue, packet)); | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 201 | if (err) | 
|  | 202 | return err; | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 203 |  | 
|  | 204 | tx_start(queue); | 
|  | 205 | octets = skb->len + txhdr_size; | 
|  | 206 | if (queue->need_workarounds) | 
|  | 207 | octets--; | 
|  | 208 | tx_data(queue, txhdr, (u8 *)skb->data, octets); | 
|  | 209 | tx_complete(queue, skb); | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 210 |  | 
|  | 211 | return 0; | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 212 | } | 
|  | 213 |  | 
|  | 214 | static void free_txpacket(struct b43legacy_pio_txpacket *packet, | 
|  | 215 | int irq_context) | 
|  | 216 | { | 
|  | 217 | struct b43legacy_pioqueue *queue = packet->queue; | 
|  | 218 |  | 
|  | 219 | if (packet->skb) { | 
|  | 220 | if (irq_context) | 
|  | 221 | dev_kfree_skb_irq(packet->skb); | 
|  | 222 | else | 
|  | 223 | dev_kfree_skb(packet->skb); | 
|  | 224 | } | 
|  | 225 | list_move(&packet->list, &queue->txfree); | 
|  | 226 | queue->nr_txfree++; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | static int pio_tx_packet(struct b43legacy_pio_txpacket *packet) | 
|  | 230 | { | 
|  | 231 | struct b43legacy_pioqueue *queue = packet->queue; | 
|  | 232 | struct sk_buff *skb = packet->skb; | 
|  | 233 | u16 octets; | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 234 | int err; | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 235 |  | 
|  | 236 | octets = (u16)skb->len + sizeof(struct b43legacy_txhdr_fw3); | 
|  | 237 | if (queue->tx_devq_size < octets) { | 
|  | 238 | b43legacywarn(queue->dev->wl, "PIO queue too small. " | 
|  | 239 | "Dropping packet.\n"); | 
|  | 240 | /* Drop it silently (return success) */ | 
|  | 241 | free_txpacket(packet, 1); | 
|  | 242 | return 0; | 
|  | 243 | } | 
|  | 244 | B43legacy_WARN_ON(queue->tx_devq_packets > | 
|  | 245 | B43legacy_PIO_MAXTXDEVQPACKETS); | 
|  | 246 | B43legacy_WARN_ON(queue->tx_devq_used > queue->tx_devq_size); | 
|  | 247 | /* Check if there is sufficient free space on the device | 
|  | 248 | * TX queue. If not, return and let the TX tasklet | 
|  | 249 | * retry later. | 
|  | 250 | */ | 
|  | 251 | if (queue->tx_devq_packets == B43legacy_PIO_MAXTXDEVQPACKETS) | 
|  | 252 | return -EBUSY; | 
|  | 253 | if (queue->tx_devq_used + octets > queue->tx_devq_size) | 
|  | 254 | return -EBUSY; | 
|  | 255 | /* Now poke the device. */ | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 256 | err = pio_tx_write_fragment(queue, skb, packet, | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 257 | sizeof(struct b43legacy_txhdr_fw3)); | 
| Stefano Brivio | 9eca9a8 | 2008-02-02 19:16:01 +0100 | [diff] [blame] | 258 | if (unlikely(err == -ENOKEY)) { | 
|  | 259 | /* Drop this packet, as we don't have the encryption key | 
|  | 260 | * anymore and must not transmit it unencrypted. */ | 
|  | 261 | free_txpacket(packet, 1); | 
|  | 262 | return 0; | 
|  | 263 | } | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 264 |  | 
|  | 265 | /* Account for the packet size. | 
|  | 266 | * (We must not overflow the device TX queue) | 
|  | 267 | */ | 
|  | 268 | queue->tx_devq_packets++; | 
|  | 269 | queue->tx_devq_used += octets; | 
|  | 270 |  | 
|  | 271 | /* Transmission started, everything ok, move the | 
|  | 272 | * packet to the txrunning list. | 
|  | 273 | */ | 
|  | 274 | list_move_tail(&packet->list, &queue->txrunning); | 
|  | 275 |  | 
|  | 276 | return 0; | 
|  | 277 | } | 
|  | 278 |  | 
|  | 279 | static void tx_tasklet(unsigned long d) | 
|  | 280 | { | 
|  | 281 | struct b43legacy_pioqueue *queue = (struct b43legacy_pioqueue *)d; | 
|  | 282 | struct b43legacy_wldev *dev = queue->dev; | 
|  | 283 | unsigned long flags; | 
|  | 284 | struct b43legacy_pio_txpacket *packet, *tmp_packet; | 
|  | 285 | int err; | 
|  | 286 | u16 txctl; | 
|  | 287 |  | 
|  | 288 | spin_lock_irqsave(&dev->wl->irq_lock, flags); | 
|  | 289 | if (queue->tx_frozen) | 
|  | 290 | goto out_unlock; | 
|  | 291 | txctl = b43legacy_pio_read(queue, B43legacy_PIO_TXCTL); | 
|  | 292 | if (txctl & B43legacy_PIO_TXCTL_SUSPEND) | 
|  | 293 | goto out_unlock; | 
|  | 294 |  | 
|  | 295 | list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) { | 
|  | 296 | /* Try to transmit the packet. This can fail, if | 
|  | 297 | * the device queue is full. In case of failure, the | 
|  | 298 | * packet is left in the txqueue. | 
|  | 299 | * If transmission succeed, the packet is moved to txrunning. | 
|  | 300 | * If it is impossible to transmit the packet, it | 
|  | 301 | * is dropped. | 
|  | 302 | */ | 
|  | 303 | err = pio_tx_packet(packet); | 
|  | 304 | if (err) | 
|  | 305 | break; | 
|  | 306 | } | 
|  | 307 | out_unlock: | 
|  | 308 | spin_unlock_irqrestore(&dev->wl->irq_lock, flags); | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | static void setup_txqueues(struct b43legacy_pioqueue *queue) | 
|  | 312 | { | 
|  | 313 | struct b43legacy_pio_txpacket *packet; | 
|  | 314 | int i; | 
|  | 315 |  | 
|  | 316 | queue->nr_txfree = B43legacy_PIO_MAXTXPACKETS; | 
|  | 317 | for (i = 0; i < B43legacy_PIO_MAXTXPACKETS; i++) { | 
|  | 318 | packet = &(queue->tx_packets_cache[i]); | 
|  | 319 |  | 
|  | 320 | packet->queue = queue; | 
|  | 321 | INIT_LIST_HEAD(&packet->list); | 
|  | 322 |  | 
|  | 323 | list_add(&packet->list, &queue->txfree); | 
|  | 324 | } | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | static | 
|  | 328 | struct b43legacy_pioqueue *b43legacy_setup_pioqueue(struct b43legacy_wldev *dev, | 
|  | 329 | u16 pio_mmio_base) | 
|  | 330 | { | 
|  | 331 | struct b43legacy_pioqueue *queue; | 
|  | 332 | u32 value; | 
|  | 333 | u16 qsize; | 
|  | 334 |  | 
|  | 335 | queue = kzalloc(sizeof(*queue), GFP_KERNEL); | 
|  | 336 | if (!queue) | 
|  | 337 | goto out; | 
|  | 338 |  | 
|  | 339 | queue->dev = dev; | 
|  | 340 | queue->mmio_base = pio_mmio_base; | 
|  | 341 | queue->need_workarounds = (dev->dev->id.revision < 3); | 
|  | 342 |  | 
|  | 343 | INIT_LIST_HEAD(&queue->txfree); | 
|  | 344 | INIT_LIST_HEAD(&queue->txqueue); | 
|  | 345 | INIT_LIST_HEAD(&queue->txrunning); | 
|  | 346 | tasklet_init(&queue->txtask, tx_tasklet, | 
|  | 347 | (unsigned long)queue); | 
|  | 348 |  | 
| Stefano Brivio | e78c9d2 | 2008-01-23 14:48:50 +0100 | [diff] [blame] | 349 | value = b43legacy_read32(dev, B43legacy_MMIO_MACCTL); | 
|  | 350 | value &= ~B43legacy_MACCTL_BE; | 
|  | 351 | b43legacy_write32(dev, B43legacy_MMIO_MACCTL, value); | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 352 |  | 
|  | 353 | qsize = b43legacy_read16(dev, queue->mmio_base | 
|  | 354 | + B43legacy_PIO_TXQBUFSIZE); | 
|  | 355 | if (qsize == 0) { | 
|  | 356 | b43legacyerr(dev->wl, "This card does not support PIO " | 
|  | 357 | "operation mode. Please use DMA mode " | 
|  | 358 | "(module parameter pio=0).\n"); | 
|  | 359 | goto err_freequeue; | 
|  | 360 | } | 
|  | 361 | if (qsize <= B43legacy_PIO_TXQADJUST) { | 
|  | 362 | b43legacyerr(dev->wl, "PIO tx device-queue too small (%u)\n", | 
|  | 363 | qsize); | 
|  | 364 | goto err_freequeue; | 
|  | 365 | } | 
|  | 366 | qsize -= B43legacy_PIO_TXQADJUST; | 
|  | 367 | queue->tx_devq_size = qsize; | 
|  | 368 |  | 
|  | 369 | setup_txqueues(queue); | 
|  | 370 |  | 
|  | 371 | out: | 
|  | 372 | return queue; | 
|  | 373 |  | 
|  | 374 | err_freequeue: | 
|  | 375 | kfree(queue); | 
|  | 376 | queue = NULL; | 
|  | 377 | goto out; | 
|  | 378 | } | 
|  | 379 |  | 
|  | 380 | static void cancel_transfers(struct b43legacy_pioqueue *queue) | 
|  | 381 | { | 
|  | 382 | struct b43legacy_pio_txpacket *packet, *tmp_packet; | 
|  | 383 |  | 
|  | 384 | tasklet_disable(&queue->txtask); | 
|  | 385 |  | 
|  | 386 | list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list) | 
|  | 387 | free_txpacket(packet, 0); | 
|  | 388 | list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) | 
|  | 389 | free_txpacket(packet, 0); | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | static void b43legacy_destroy_pioqueue(struct b43legacy_pioqueue *queue) | 
|  | 393 | { | 
|  | 394 | if (!queue) | 
|  | 395 | return; | 
|  | 396 |  | 
|  | 397 | cancel_transfers(queue); | 
|  | 398 | kfree(queue); | 
|  | 399 | } | 
|  | 400 |  | 
|  | 401 | void b43legacy_pio_free(struct b43legacy_wldev *dev) | 
|  | 402 | { | 
|  | 403 | struct b43legacy_pio *pio; | 
|  | 404 |  | 
|  | 405 | if (!b43legacy_using_pio(dev)) | 
|  | 406 | return; | 
|  | 407 | pio = &dev->pio; | 
|  | 408 |  | 
|  | 409 | b43legacy_destroy_pioqueue(pio->queue3); | 
|  | 410 | pio->queue3 = NULL; | 
|  | 411 | b43legacy_destroy_pioqueue(pio->queue2); | 
|  | 412 | pio->queue2 = NULL; | 
|  | 413 | b43legacy_destroy_pioqueue(pio->queue1); | 
|  | 414 | pio->queue1 = NULL; | 
|  | 415 | b43legacy_destroy_pioqueue(pio->queue0); | 
|  | 416 | pio->queue0 = NULL; | 
|  | 417 | } | 
|  | 418 |  | 
|  | 419 | int b43legacy_pio_init(struct b43legacy_wldev *dev) | 
|  | 420 | { | 
|  | 421 | struct b43legacy_pio *pio = &dev->pio; | 
|  | 422 | struct b43legacy_pioqueue *queue; | 
|  | 423 | int err = -ENOMEM; | 
|  | 424 |  | 
|  | 425 | queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO1_BASE); | 
|  | 426 | if (!queue) | 
|  | 427 | goto out; | 
|  | 428 | pio->queue0 = queue; | 
|  | 429 |  | 
|  | 430 | queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO2_BASE); | 
|  | 431 | if (!queue) | 
|  | 432 | goto err_destroy0; | 
|  | 433 | pio->queue1 = queue; | 
|  | 434 |  | 
|  | 435 | queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO3_BASE); | 
|  | 436 | if (!queue) | 
|  | 437 | goto err_destroy1; | 
|  | 438 | pio->queue2 = queue; | 
|  | 439 |  | 
|  | 440 | queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO4_BASE); | 
|  | 441 | if (!queue) | 
|  | 442 | goto err_destroy2; | 
|  | 443 | pio->queue3 = queue; | 
|  | 444 |  | 
|  | 445 | if (dev->dev->id.revision < 3) | 
|  | 446 | dev->irq_savedstate |= B43legacy_IRQ_PIO_WORKAROUND; | 
|  | 447 |  | 
|  | 448 | b43legacydbg(dev->wl, "PIO initialized\n"); | 
|  | 449 | err = 0; | 
|  | 450 | out: | 
|  | 451 | return err; | 
|  | 452 |  | 
|  | 453 | err_destroy2: | 
|  | 454 | b43legacy_destroy_pioqueue(pio->queue2); | 
|  | 455 | pio->queue2 = NULL; | 
|  | 456 | err_destroy1: | 
|  | 457 | b43legacy_destroy_pioqueue(pio->queue1); | 
|  | 458 | pio->queue1 = NULL; | 
|  | 459 | err_destroy0: | 
|  | 460 | b43legacy_destroy_pioqueue(pio->queue0); | 
|  | 461 | pio->queue0 = NULL; | 
|  | 462 | goto out; | 
|  | 463 | } | 
|  | 464 |  | 
|  | 465 | int b43legacy_pio_tx(struct b43legacy_wldev *dev, | 
|  | 466 | struct sk_buff *skb, | 
|  | 467 | struct ieee80211_tx_control *ctl) | 
|  | 468 | { | 
|  | 469 | struct b43legacy_pioqueue *queue = dev->pio.queue1; | 
|  | 470 | struct b43legacy_pio_txpacket *packet; | 
|  | 471 |  | 
|  | 472 | B43legacy_WARN_ON(queue->tx_suspended); | 
|  | 473 | B43legacy_WARN_ON(list_empty(&queue->txfree)); | 
|  | 474 |  | 
|  | 475 | packet = list_entry(queue->txfree.next, struct b43legacy_pio_txpacket, | 
|  | 476 | list); | 
|  | 477 | packet->skb = skb; | 
|  | 478 |  | 
|  | 479 | memset(&packet->txstat, 0, sizeof(packet->txstat)); | 
|  | 480 | memcpy(&packet->txstat.control, ctl, sizeof(*ctl)); | 
|  | 481 |  | 
|  | 482 | list_move_tail(&packet->list, &queue->txqueue); | 
|  | 483 | queue->nr_txfree--; | 
|  | 484 | queue->nr_tx_packets++; | 
|  | 485 | B43legacy_WARN_ON(queue->nr_txfree >= B43legacy_PIO_MAXTXPACKETS); | 
|  | 486 |  | 
|  | 487 | tasklet_schedule(&queue->txtask); | 
|  | 488 |  | 
|  | 489 | return 0; | 
|  | 490 | } | 
|  | 491 |  | 
|  | 492 | void b43legacy_pio_handle_txstatus(struct b43legacy_wldev *dev, | 
|  | 493 | const struct b43legacy_txstatus *status) | 
|  | 494 | { | 
|  | 495 | struct b43legacy_pioqueue *queue; | 
|  | 496 | struct b43legacy_pio_txpacket *packet; | 
|  | 497 |  | 
|  | 498 | queue = parse_cookie(dev, status->cookie, &packet); | 
|  | 499 | B43legacy_WARN_ON(!queue); | 
|  | 500 |  | 
| Stefano Brivio | 0cd67d4 | 2008-02-02 19:15:49 +0100 | [diff] [blame] | 501 | if (!packet->skb) | 
|  | 502 | return; | 
|  | 503 |  | 
| Larry Finger | 75388ac | 2007-09-25 16:46:54 -0700 | [diff] [blame] | 504 | queue->tx_devq_packets--; | 
|  | 505 | queue->tx_devq_used -= (packet->skb->len + | 
|  | 506 | sizeof(struct b43legacy_txhdr_fw3)); | 
|  | 507 |  | 
|  | 508 | if (status->acked) | 
|  | 509 | packet->txstat.flags |= IEEE80211_TX_STATUS_ACK; | 
|  | 510 | packet->txstat.retry_count = status->frame_count - 1; | 
|  | 511 | ieee80211_tx_status_irqsafe(dev->wl->hw, packet->skb, | 
|  | 512 | &(packet->txstat)); | 
|  | 513 | packet->skb = NULL; | 
|  | 514 |  | 
|  | 515 | free_txpacket(packet, 1); | 
|  | 516 | /* If there are packets on the txqueue, poke the tasklet | 
|  | 517 | * to transmit them. | 
|  | 518 | */ | 
|  | 519 | if (!list_empty(&queue->txqueue)) | 
|  | 520 | tasklet_schedule(&queue->txtask); | 
|  | 521 | } | 
|  | 522 |  | 
|  | 523 | void b43legacy_pio_get_tx_stats(struct b43legacy_wldev *dev, | 
|  | 524 | struct ieee80211_tx_queue_stats *stats) | 
|  | 525 | { | 
|  | 526 | struct b43legacy_pio *pio = &dev->pio; | 
|  | 527 | struct b43legacy_pioqueue *queue; | 
|  | 528 | struct ieee80211_tx_queue_stats_data *data; | 
|  | 529 |  | 
|  | 530 | queue = pio->queue1; | 
|  | 531 | data = &(stats->data[0]); | 
|  | 532 | data->len = B43legacy_PIO_MAXTXPACKETS - queue->nr_txfree; | 
|  | 533 | data->limit = B43legacy_PIO_MAXTXPACKETS; | 
|  | 534 | data->count = queue->nr_tx_packets; | 
|  | 535 | } | 
|  | 536 |  | 
|  | 537 | static void pio_rx_error(struct b43legacy_pioqueue *queue, | 
|  | 538 | int clear_buffers, | 
|  | 539 | const char *error) | 
|  | 540 | { | 
|  | 541 | int i; | 
|  | 542 |  | 
|  | 543 | b43legacyerr(queue->dev->wl, "PIO RX error: %s\n", error); | 
|  | 544 | b43legacy_pio_write(queue, B43legacy_PIO_RXCTL, | 
|  | 545 | B43legacy_PIO_RXCTL_READY); | 
|  | 546 | if (clear_buffers) { | 
|  | 547 | B43legacy_WARN_ON(queue->mmio_base != B43legacy_MMIO_PIO1_BASE); | 
|  | 548 | for (i = 0; i < 15; i++) { | 
|  | 549 | /* Dummy read. */ | 
|  | 550 | b43legacy_pio_read(queue, B43legacy_PIO_RXDATA); | 
|  | 551 | } | 
|  | 552 | } | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | void b43legacy_pio_rx(struct b43legacy_pioqueue *queue) | 
|  | 556 | { | 
|  | 557 | __le16 preamble[21] = { 0 }; | 
|  | 558 | struct b43legacy_rxhdr_fw3 *rxhdr; | 
|  | 559 | u16 tmp; | 
|  | 560 | u16 len; | 
|  | 561 | u16 macstat; | 
|  | 562 | int i; | 
|  | 563 | int preamble_readwords; | 
|  | 564 | struct sk_buff *skb; | 
|  | 565 |  | 
|  | 566 | tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXCTL); | 
|  | 567 | if (!(tmp & B43legacy_PIO_RXCTL_DATAAVAILABLE)) | 
|  | 568 | return; | 
|  | 569 | b43legacy_pio_write(queue, B43legacy_PIO_RXCTL, | 
|  | 570 | B43legacy_PIO_RXCTL_DATAAVAILABLE); | 
|  | 571 |  | 
|  | 572 | for (i = 0; i < 10; i++) { | 
|  | 573 | tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXCTL); | 
|  | 574 | if (tmp & B43legacy_PIO_RXCTL_READY) | 
|  | 575 | goto data_ready; | 
|  | 576 | udelay(10); | 
|  | 577 | } | 
|  | 578 | b43legacydbg(queue->dev->wl, "PIO RX timed out\n"); | 
|  | 579 | return; | 
|  | 580 | data_ready: | 
|  | 581 |  | 
|  | 582 | len = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA); | 
|  | 583 | if (unlikely(len > 0x700)) { | 
|  | 584 | pio_rx_error(queue, 0, "len > 0x700"); | 
|  | 585 | return; | 
|  | 586 | } | 
|  | 587 | if (unlikely(len == 0 && queue->mmio_base != | 
|  | 588 | B43legacy_MMIO_PIO4_BASE)) { | 
|  | 589 | pio_rx_error(queue, 0, "len == 0"); | 
|  | 590 | return; | 
|  | 591 | } | 
|  | 592 | preamble[0] = cpu_to_le16(len); | 
|  | 593 | if (queue->mmio_base == B43legacy_MMIO_PIO4_BASE) | 
|  | 594 | preamble_readwords = 14 / sizeof(u16); | 
|  | 595 | else | 
|  | 596 | preamble_readwords = 18 / sizeof(u16); | 
|  | 597 | for (i = 0; i < preamble_readwords; i++) { | 
|  | 598 | tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA); | 
|  | 599 | preamble[i + 1] = cpu_to_le16(tmp); | 
|  | 600 | } | 
|  | 601 | rxhdr = (struct b43legacy_rxhdr_fw3 *)preamble; | 
|  | 602 | macstat = le16_to_cpu(rxhdr->mac_status); | 
|  | 603 | if (macstat & B43legacy_RX_MAC_FCSERR) { | 
|  | 604 | pio_rx_error(queue, | 
|  | 605 | (queue->mmio_base == B43legacy_MMIO_PIO1_BASE), | 
|  | 606 | "Frame FCS error"); | 
|  | 607 | return; | 
|  | 608 | } | 
|  | 609 | if (queue->mmio_base == B43legacy_MMIO_PIO4_BASE) { | 
|  | 610 | /* We received an xmit status. */ | 
|  | 611 | struct b43legacy_hwtxstatus *hw; | 
|  | 612 |  | 
|  | 613 | hw = (struct b43legacy_hwtxstatus *)(preamble + 1); | 
|  | 614 | b43legacy_handle_hwtxstatus(queue->dev, hw); | 
|  | 615 |  | 
|  | 616 | return; | 
|  | 617 | } | 
|  | 618 |  | 
|  | 619 | skb = dev_alloc_skb(len); | 
|  | 620 | if (unlikely(!skb)) { | 
|  | 621 | pio_rx_error(queue, 1, "OOM"); | 
|  | 622 | return; | 
|  | 623 | } | 
|  | 624 | skb_put(skb, len); | 
|  | 625 | for (i = 0; i < len - 1; i += 2) { | 
|  | 626 | tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA); | 
|  | 627 | *((__le16 *)(skb->data + i)) = cpu_to_le16(tmp); | 
|  | 628 | } | 
|  | 629 | if (len % 2) { | 
|  | 630 | tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA); | 
|  | 631 | skb->data[len - 1] = (tmp & 0x00FF); | 
|  | 632 | } | 
|  | 633 | b43legacy_rx(queue->dev, skb, rxhdr); | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | void b43legacy_pio_tx_suspend(struct b43legacy_pioqueue *queue) | 
|  | 637 | { | 
|  | 638 | b43legacy_power_saving_ctl_bits(queue->dev, -1, 1); | 
|  | 639 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 640 | b43legacy_pio_read(queue, B43legacy_PIO_TXCTL) | 
|  | 641 | | B43legacy_PIO_TXCTL_SUSPEND); | 
|  | 642 | } | 
|  | 643 |  | 
|  | 644 | void b43legacy_pio_tx_resume(struct b43legacy_pioqueue *queue) | 
|  | 645 | { | 
|  | 646 | b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, | 
|  | 647 | b43legacy_pio_read(queue, B43legacy_PIO_TXCTL) | 
|  | 648 | & ~B43legacy_PIO_TXCTL_SUSPEND); | 
|  | 649 | b43legacy_power_saving_ctl_bits(queue->dev, -1, -1); | 
|  | 650 | tasklet_schedule(&queue->txtask); | 
|  | 651 | } | 
|  | 652 |  | 
|  | 653 | void b43legacy_pio_freeze_txqueues(struct b43legacy_wldev *dev) | 
|  | 654 | { | 
|  | 655 | struct b43legacy_pio *pio; | 
|  | 656 |  | 
|  | 657 | B43legacy_WARN_ON(!b43legacy_using_pio(dev)); | 
|  | 658 | pio = &dev->pio; | 
|  | 659 | pio->queue0->tx_frozen = 1; | 
|  | 660 | pio->queue1->tx_frozen = 1; | 
|  | 661 | pio->queue2->tx_frozen = 1; | 
|  | 662 | pio->queue3->tx_frozen = 1; | 
|  | 663 | } | 
|  | 664 |  | 
|  | 665 | void b43legacy_pio_thaw_txqueues(struct b43legacy_wldev *dev) | 
|  | 666 | { | 
|  | 667 | struct b43legacy_pio *pio; | 
|  | 668 |  | 
|  | 669 | B43legacy_WARN_ON(!b43legacy_using_pio(dev)); | 
|  | 670 | pio = &dev->pio; | 
|  | 671 | pio->queue0->tx_frozen = 0; | 
|  | 672 | pio->queue1->tx_frozen = 0; | 
|  | 673 | pio->queue2->tx_frozen = 0; | 
|  | 674 | pio->queue3->tx_frozen = 0; | 
|  | 675 | if (!list_empty(&pio->queue0->txqueue)) | 
|  | 676 | tasklet_schedule(&pio->queue0->txtask); | 
|  | 677 | if (!list_empty(&pio->queue1->txqueue)) | 
|  | 678 | tasklet_schedule(&pio->queue1->txtask); | 
|  | 679 | if (!list_empty(&pio->queue2->txqueue)) | 
|  | 680 | tasklet_schedule(&pio->queue2->txtask); | 
|  | 681 | if (!list_empty(&pio->queue3->txqueue)) | 
|  | 682 | tasklet_schedule(&pio->queue3->txtask); | 
|  | 683 | } |