Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Broadcom B43 wireless driver |
| 4 | |
| 5 | PIO data transfer |
| 6 | |
| 7 | Copyright (c) 2005-2008 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 "b43.h" |
| 27 | #include "pio.h" |
| 28 | #include "dma.h" |
| 29 | #include "main.h" |
| 30 | #include "xmit.h" |
| 31 | |
| 32 | #include <linux/delay.h> |
| 33 | |
| 34 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 35 | static u16 generate_cookie(struct b43_pio_txqueue *q, |
| 36 | struct b43_pio_txpacket *pack) |
| 37 | { |
| 38 | u16 cookie; |
| 39 | |
| 40 | /* Use the upper 4 bits of the cookie as |
| 41 | * PIO controller ID and store the packet index number |
| 42 | * in the lower 12 bits. |
| 43 | * Note that the cookie must never be 0, as this |
| 44 | * is a special value used in RX path. |
| 45 | * It can also not be 0xFFFF because that is special |
| 46 | * for multicast frames. |
| 47 | */ |
| 48 | cookie = (((u16)q->index + 1) << 12); |
| 49 | cookie |= pack->index; |
| 50 | |
| 51 | return cookie; |
| 52 | } |
| 53 | |
| 54 | static |
John Daiker | 99da185 | 2009-02-24 02:16:42 -0800 | [diff] [blame] | 55 | struct b43_pio_txqueue *parse_cookie(struct b43_wldev *dev, |
| 56 | u16 cookie, |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 57 | struct b43_pio_txpacket **pack) |
| 58 | { |
| 59 | struct b43_pio *pio = &dev->pio; |
| 60 | struct b43_pio_txqueue *q = NULL; |
| 61 | unsigned int pack_index; |
| 62 | |
| 63 | switch (cookie & 0xF000) { |
| 64 | case 0x1000: |
| 65 | q = pio->tx_queue_AC_BK; |
| 66 | break; |
| 67 | case 0x2000: |
| 68 | q = pio->tx_queue_AC_BE; |
| 69 | break; |
| 70 | case 0x3000: |
| 71 | q = pio->tx_queue_AC_VI; |
| 72 | break; |
| 73 | case 0x4000: |
| 74 | q = pio->tx_queue_AC_VO; |
| 75 | break; |
| 76 | case 0x5000: |
| 77 | q = pio->tx_queue_mcast; |
| 78 | break; |
| 79 | } |
| 80 | if (B43_WARN_ON(!q)) |
| 81 | return NULL; |
| 82 | pack_index = (cookie & 0x0FFF); |
| 83 | if (B43_WARN_ON(pack_index >= ARRAY_SIZE(q->packets))) |
| 84 | return NULL; |
| 85 | *pack = &q->packets[pack_index]; |
| 86 | |
| 87 | return q; |
| 88 | } |
| 89 | |
| 90 | static u16 index_to_pioqueue_base(struct b43_wldev *dev, |
| 91 | unsigned int index) |
| 92 | { |
| 93 | static const u16 bases[] = { |
| 94 | B43_MMIO_PIO_BASE0, |
| 95 | B43_MMIO_PIO_BASE1, |
| 96 | B43_MMIO_PIO_BASE2, |
| 97 | B43_MMIO_PIO_BASE3, |
| 98 | B43_MMIO_PIO_BASE4, |
| 99 | B43_MMIO_PIO_BASE5, |
| 100 | B43_MMIO_PIO_BASE6, |
| 101 | B43_MMIO_PIO_BASE7, |
| 102 | }; |
| 103 | static const u16 bases_rev11[] = { |
| 104 | B43_MMIO_PIO11_BASE0, |
| 105 | B43_MMIO_PIO11_BASE1, |
| 106 | B43_MMIO_PIO11_BASE2, |
| 107 | B43_MMIO_PIO11_BASE3, |
| 108 | B43_MMIO_PIO11_BASE4, |
| 109 | B43_MMIO_PIO11_BASE5, |
| 110 | }; |
| 111 | |
| 112 | if (dev->dev->id.revision >= 11) { |
| 113 | B43_WARN_ON(index >= ARRAY_SIZE(bases_rev11)); |
| 114 | return bases_rev11[index]; |
| 115 | } |
| 116 | B43_WARN_ON(index >= ARRAY_SIZE(bases)); |
| 117 | return bases[index]; |
| 118 | } |
| 119 | |
| 120 | static u16 pio_txqueue_offset(struct b43_wldev *dev) |
| 121 | { |
| 122 | if (dev->dev->id.revision >= 11) |
| 123 | return 0x18; |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static u16 pio_rxqueue_offset(struct b43_wldev *dev) |
| 128 | { |
| 129 | if (dev->dev->id.revision >= 11) |
| 130 | return 0x38; |
| 131 | return 8; |
| 132 | } |
| 133 | |
John Daiker | 99da185 | 2009-02-24 02:16:42 -0800 | [diff] [blame] | 134 | static struct b43_pio_txqueue *b43_setup_pioqueue_tx(struct b43_wldev *dev, |
| 135 | unsigned int index) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 136 | { |
| 137 | struct b43_pio_txqueue *q; |
| 138 | struct b43_pio_txpacket *p; |
| 139 | unsigned int i; |
| 140 | |
| 141 | q = kzalloc(sizeof(*q), GFP_KERNEL); |
| 142 | if (!q) |
| 143 | return NULL; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 144 | q->dev = dev; |
| 145 | q->rev = dev->dev->id.revision; |
| 146 | q->mmio_base = index_to_pioqueue_base(dev, index) + |
| 147 | pio_txqueue_offset(dev); |
| 148 | q->index = index; |
| 149 | |
| 150 | q->free_packet_slots = B43_PIO_MAX_NR_TXPACKETS; |
| 151 | if (q->rev >= 8) { |
| 152 | q->buffer_size = 1920; //FIXME this constant is wrong. |
| 153 | } else { |
| 154 | q->buffer_size = b43_piotx_read16(q, B43_PIO_TXQBUFSIZE); |
| 155 | q->buffer_size -= 80; |
| 156 | } |
| 157 | |
| 158 | INIT_LIST_HEAD(&q->packets_list); |
| 159 | for (i = 0; i < ARRAY_SIZE(q->packets); i++) { |
| 160 | p = &(q->packets[i]); |
| 161 | INIT_LIST_HEAD(&p->list); |
| 162 | p->index = i; |
| 163 | p->queue = q; |
| 164 | list_add(&p->list, &q->packets_list); |
| 165 | } |
| 166 | |
| 167 | return q; |
| 168 | } |
| 169 | |
John Daiker | 99da185 | 2009-02-24 02:16:42 -0800 | [diff] [blame] | 170 | static struct b43_pio_rxqueue *b43_setup_pioqueue_rx(struct b43_wldev *dev, |
| 171 | unsigned int index) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 172 | { |
| 173 | struct b43_pio_rxqueue *q; |
| 174 | |
| 175 | q = kzalloc(sizeof(*q), GFP_KERNEL); |
| 176 | if (!q) |
| 177 | return NULL; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 178 | q->dev = dev; |
| 179 | q->rev = dev->dev->id.revision; |
| 180 | q->mmio_base = index_to_pioqueue_base(dev, index) + |
| 181 | pio_rxqueue_offset(dev); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 182 | |
| 183 | /* Enable Direct FIFO RX (PIO) on the engine. */ |
| 184 | b43_dma_direct_fifo_rx(dev, index, 1); |
| 185 | |
| 186 | return q; |
| 187 | } |
| 188 | |
| 189 | static void b43_pio_cancel_tx_packets(struct b43_pio_txqueue *q) |
| 190 | { |
| 191 | struct b43_pio_txpacket *pack; |
| 192 | unsigned int i; |
| 193 | |
| 194 | for (i = 0; i < ARRAY_SIZE(q->packets); i++) { |
| 195 | pack = &(q->packets[i]); |
| 196 | if (pack->skb) { |
| 197 | dev_kfree_skb_any(pack->skb); |
| 198 | pack->skb = NULL; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | static void b43_destroy_pioqueue_tx(struct b43_pio_txqueue *q, |
| 204 | const char *name) |
| 205 | { |
| 206 | if (!q) |
| 207 | return; |
| 208 | b43_pio_cancel_tx_packets(q); |
| 209 | kfree(q); |
| 210 | } |
| 211 | |
| 212 | static void b43_destroy_pioqueue_rx(struct b43_pio_rxqueue *q, |
| 213 | const char *name) |
| 214 | { |
| 215 | if (!q) |
| 216 | return; |
| 217 | kfree(q); |
| 218 | } |
| 219 | |
| 220 | #define destroy_queue_tx(pio, queue) do { \ |
| 221 | b43_destroy_pioqueue_tx((pio)->queue, __stringify(queue)); \ |
| 222 | (pio)->queue = NULL; \ |
| 223 | } while (0) |
| 224 | |
| 225 | #define destroy_queue_rx(pio, queue) do { \ |
| 226 | b43_destroy_pioqueue_rx((pio)->queue, __stringify(queue)); \ |
| 227 | (pio)->queue = NULL; \ |
| 228 | } while (0) |
| 229 | |
| 230 | void b43_pio_free(struct b43_wldev *dev) |
| 231 | { |
| 232 | struct b43_pio *pio; |
| 233 | |
| 234 | if (!b43_using_pio_transfers(dev)) |
| 235 | return; |
| 236 | pio = &dev->pio; |
| 237 | |
| 238 | destroy_queue_rx(pio, rx_queue); |
| 239 | destroy_queue_tx(pio, tx_queue_mcast); |
| 240 | destroy_queue_tx(pio, tx_queue_AC_VO); |
| 241 | destroy_queue_tx(pio, tx_queue_AC_VI); |
| 242 | destroy_queue_tx(pio, tx_queue_AC_BE); |
| 243 | destroy_queue_tx(pio, tx_queue_AC_BK); |
| 244 | } |
| 245 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 246 | int b43_pio_init(struct b43_wldev *dev) |
| 247 | { |
| 248 | struct b43_pio *pio = &dev->pio; |
| 249 | int err = -ENOMEM; |
| 250 | |
| 251 | b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL) |
| 252 | & ~B43_MACCTL_BE); |
| 253 | b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_RXPADOFF, 0); |
| 254 | |
| 255 | pio->tx_queue_AC_BK = b43_setup_pioqueue_tx(dev, 0); |
| 256 | if (!pio->tx_queue_AC_BK) |
| 257 | goto out; |
| 258 | |
| 259 | pio->tx_queue_AC_BE = b43_setup_pioqueue_tx(dev, 1); |
| 260 | if (!pio->tx_queue_AC_BE) |
| 261 | goto err_destroy_bk; |
| 262 | |
| 263 | pio->tx_queue_AC_VI = b43_setup_pioqueue_tx(dev, 2); |
| 264 | if (!pio->tx_queue_AC_VI) |
| 265 | goto err_destroy_be; |
| 266 | |
| 267 | pio->tx_queue_AC_VO = b43_setup_pioqueue_tx(dev, 3); |
| 268 | if (!pio->tx_queue_AC_VO) |
| 269 | goto err_destroy_vi; |
| 270 | |
| 271 | pio->tx_queue_mcast = b43_setup_pioqueue_tx(dev, 4); |
| 272 | if (!pio->tx_queue_mcast) |
| 273 | goto err_destroy_vo; |
| 274 | |
| 275 | pio->rx_queue = b43_setup_pioqueue_rx(dev, 0); |
| 276 | if (!pio->rx_queue) |
| 277 | goto err_destroy_mcast; |
| 278 | |
| 279 | b43dbg(dev->wl, "PIO initialized\n"); |
| 280 | err = 0; |
| 281 | out: |
| 282 | return err; |
| 283 | |
| 284 | err_destroy_mcast: |
| 285 | destroy_queue_tx(pio, tx_queue_mcast); |
| 286 | err_destroy_vo: |
| 287 | destroy_queue_tx(pio, tx_queue_AC_VO); |
| 288 | err_destroy_vi: |
| 289 | destroy_queue_tx(pio, tx_queue_AC_VI); |
| 290 | err_destroy_be: |
| 291 | destroy_queue_tx(pio, tx_queue_AC_BE); |
| 292 | err_destroy_bk: |
| 293 | destroy_queue_tx(pio, tx_queue_AC_BK); |
| 294 | return err; |
| 295 | } |
| 296 | |
| 297 | /* Static mapping of mac80211's queues (priorities) to b43 PIO queues. */ |
John Daiker | 99da185 | 2009-02-24 02:16:42 -0800 | [diff] [blame] | 298 | static struct b43_pio_txqueue *select_queue_by_priority(struct b43_wldev *dev, |
| 299 | u8 queue_prio) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 300 | { |
| 301 | struct b43_pio_txqueue *q; |
| 302 | |
Michael Buesch | 403a3a1 | 2009-06-08 21:04:57 +0200 | [diff] [blame] | 303 | if (dev->qos_enabled) { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 304 | /* 0 = highest priority */ |
| 305 | switch (queue_prio) { |
| 306 | default: |
| 307 | B43_WARN_ON(1); |
| 308 | /* fallthrough */ |
| 309 | case 0: |
| 310 | q = dev->pio.tx_queue_AC_VO; |
| 311 | break; |
| 312 | case 1: |
| 313 | q = dev->pio.tx_queue_AC_VI; |
| 314 | break; |
| 315 | case 2: |
| 316 | q = dev->pio.tx_queue_AC_BE; |
| 317 | break; |
| 318 | case 3: |
| 319 | q = dev->pio.tx_queue_AC_BK; |
| 320 | break; |
| 321 | } |
| 322 | } else |
| 323 | q = dev->pio.tx_queue_AC_BE; |
| 324 | |
| 325 | return q; |
| 326 | } |
| 327 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 328 | static u16 tx_write_2byte_queue(struct b43_pio_txqueue *q, |
| 329 | u16 ctl, |
| 330 | const void *_data, |
| 331 | unsigned int data_len) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 332 | { |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 333 | struct b43_wldev *dev = q->dev; |
Albert Herranz | 7e937c6 | 2009-10-07 00:07:44 +0200 | [diff] [blame] | 334 | struct b43_wl *wl = dev->wl; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 335 | const u8 *data = _data; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 336 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 337 | ctl |= B43_PIO_TXCTL_WRITELO | B43_PIO_TXCTL_WRITEHI; |
| 338 | b43_piotx_write16(q, B43_PIO_TXCTL, ctl); |
| 339 | |
| 340 | ssb_block_write(dev->dev, data, (data_len & ~1), |
| 341 | q->mmio_base + B43_PIO_TXDATA, |
| 342 | sizeof(u16)); |
| 343 | if (data_len & 1) { |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 344 | u8 *tail = wl->pio_tailspace; |
| 345 | BUILD_BUG_ON(sizeof(wl->pio_tailspace) < 2); |
| 346 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 347 | /* Write the last byte. */ |
| 348 | ctl &= ~B43_PIO_TXCTL_WRITEHI; |
| 349 | b43_piotx_write16(q, B43_PIO_TXCTL, ctl); |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 350 | tail[0] = data[data_len - 1]; |
| 351 | tail[1] = 0; |
| 352 | ssb_block_write(dev->dev, tail, 2, |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 353 | q->mmio_base + B43_PIO_TXDATA, |
| 354 | sizeof(u16)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 355 | } |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 356 | |
| 357 | return ctl; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static void pio_tx_frame_2byte_queue(struct b43_pio_txpacket *pack, |
| 361 | const u8 *hdr, unsigned int hdrlen) |
| 362 | { |
| 363 | struct b43_pio_txqueue *q = pack->queue; |
| 364 | const char *frame = pack->skb->data; |
| 365 | unsigned int frame_len = pack->skb->len; |
| 366 | u16 ctl; |
| 367 | |
| 368 | ctl = b43_piotx_read16(q, B43_PIO_TXCTL); |
| 369 | ctl |= B43_PIO_TXCTL_FREADY; |
| 370 | ctl &= ~B43_PIO_TXCTL_EOF; |
| 371 | |
| 372 | /* Transfer the header data. */ |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 373 | ctl = tx_write_2byte_queue(q, ctl, hdr, hdrlen); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 374 | /* Transfer the frame data. */ |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 375 | ctl = tx_write_2byte_queue(q, ctl, frame, frame_len); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 376 | |
| 377 | ctl |= B43_PIO_TXCTL_EOF; |
| 378 | b43_piotx_write16(q, B43_PIO_TXCTL, ctl); |
| 379 | } |
| 380 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 381 | static u32 tx_write_4byte_queue(struct b43_pio_txqueue *q, |
| 382 | u32 ctl, |
| 383 | const void *_data, |
| 384 | unsigned int data_len) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 385 | { |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 386 | struct b43_wldev *dev = q->dev; |
Albert Herranz | 7e937c6 | 2009-10-07 00:07:44 +0200 | [diff] [blame] | 387 | struct b43_wl *wl = dev->wl; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 388 | const u8 *data = _data; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 389 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 390 | ctl |= B43_PIO8_TXCTL_0_7 | B43_PIO8_TXCTL_8_15 | |
| 391 | B43_PIO8_TXCTL_16_23 | B43_PIO8_TXCTL_24_31; |
| 392 | b43_piotx_write32(q, B43_PIO8_TXCTL, ctl); |
| 393 | |
| 394 | ssb_block_write(dev->dev, data, (data_len & ~3), |
| 395 | q->mmio_base + B43_PIO8_TXDATA, |
| 396 | sizeof(u32)); |
| 397 | if (data_len & 3) { |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 398 | u8 *tail = wl->pio_tailspace; |
| 399 | BUILD_BUG_ON(sizeof(wl->pio_tailspace) < 4); |
| 400 | |
| 401 | memset(tail, 0, 4); |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 402 | /* Write the last few bytes. */ |
| 403 | ctl &= ~(B43_PIO8_TXCTL_8_15 | B43_PIO8_TXCTL_16_23 | |
| 404 | B43_PIO8_TXCTL_24_31); |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 405 | switch (data_len & 3) { |
| 406 | case 3: |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 407 | ctl |= B43_PIO8_TXCTL_16_23 | B43_PIO8_TXCTL_8_15; |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 408 | tail[0] = data[data_len - 3]; |
| 409 | tail[1] = data[data_len - 2]; |
| 410 | tail[2] = data[data_len - 1]; |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 411 | break; |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 412 | case 2: |
| 413 | ctl |= B43_PIO8_TXCTL_8_15; |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 414 | tail[0] = data[data_len - 2]; |
| 415 | tail[1] = data[data_len - 1]; |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 416 | break; |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 417 | case 1: |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 418 | tail[0] = data[data_len - 1]; |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 419 | break; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 420 | } |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 421 | b43_piotx_write32(q, B43_PIO8_TXCTL, ctl); |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 422 | ssb_block_write(dev->dev, tail, 4, |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 423 | q->mmio_base + B43_PIO8_TXDATA, |
| 424 | sizeof(u32)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 425 | } |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 426 | |
| 427 | return ctl; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void pio_tx_frame_4byte_queue(struct b43_pio_txpacket *pack, |
| 431 | const u8 *hdr, unsigned int hdrlen) |
| 432 | { |
| 433 | struct b43_pio_txqueue *q = pack->queue; |
| 434 | const char *frame = pack->skb->data; |
| 435 | unsigned int frame_len = pack->skb->len; |
| 436 | u32 ctl; |
| 437 | |
| 438 | ctl = b43_piotx_read32(q, B43_PIO8_TXCTL); |
| 439 | ctl |= B43_PIO8_TXCTL_FREADY; |
| 440 | ctl &= ~B43_PIO8_TXCTL_EOF; |
| 441 | |
| 442 | /* Transfer the header data. */ |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 443 | ctl = tx_write_4byte_queue(q, ctl, hdr, hdrlen); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 444 | /* Transfer the frame data. */ |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 445 | ctl = tx_write_4byte_queue(q, ctl, frame, frame_len); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 446 | |
| 447 | ctl |= B43_PIO8_TXCTL_EOF; |
| 448 | b43_piotx_write32(q, B43_PIO_TXCTL, ctl); |
| 449 | } |
| 450 | |
| 451 | static int pio_tx_frame(struct b43_pio_txqueue *q, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 452 | struct sk_buff *skb) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 453 | { |
Albert Herranz | 7e937c6 | 2009-10-07 00:07:44 +0200 | [diff] [blame] | 454 | struct b43_wldev *dev = q->dev; |
| 455 | struct b43_wl *wl = dev->wl; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 456 | struct b43_pio_txpacket *pack; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 457 | u16 cookie; |
| 458 | int err; |
| 459 | unsigned int hdrlen; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 460 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 461 | struct b43_txhdr *txhdr = (struct b43_txhdr *)wl->pio_scratchspace; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 462 | |
| 463 | B43_WARN_ON(list_empty(&q->packets_list)); |
| 464 | pack = list_entry(q->packets_list.next, |
| 465 | struct b43_pio_txpacket, list); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 466 | |
| 467 | cookie = generate_cookie(q, pack); |
Albert Herranz | 7e937c6 | 2009-10-07 00:07:44 +0200 | [diff] [blame] | 468 | hdrlen = b43_txhdr_size(dev); |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 469 | BUILD_BUG_ON(sizeof(wl->pio_scratchspace) < sizeof(struct b43_txhdr)); |
| 470 | B43_WARN_ON(sizeof(wl->pio_scratchspace) < hdrlen); |
| 471 | err = b43_generate_txhdr(dev, (u8 *)txhdr, skb, |
gregor kowski | 035d024 | 2009-08-19 22:35:45 +0200 | [diff] [blame] | 472 | info, cookie); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 473 | if (err) |
| 474 | return err; |
| 475 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 476 | if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 477 | /* Tell the firmware about the cookie of the last |
| 478 | * mcast frame, so it can clear the more-data bit in it. */ |
Albert Herranz | 7e937c6 | 2009-10-07 00:07:44 +0200 | [diff] [blame] | 479 | b43_shm_write16(dev, B43_SHM_SHARED, |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 480 | B43_SHM_SH_MCASTCOOKIE, cookie); |
| 481 | } |
| 482 | |
| 483 | pack->skb = skb; |
| 484 | if (q->rev >= 8) |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 485 | pio_tx_frame_4byte_queue(pack, (const u8 *)txhdr, hdrlen); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 486 | else |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 487 | pio_tx_frame_2byte_queue(pack, (const u8 *)txhdr, hdrlen); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 488 | |
| 489 | /* Remove it from the list of available packet slots. |
| 490 | * It will be put back when we receive the status report. */ |
| 491 | list_del(&pack->list); |
| 492 | |
| 493 | /* Update the queue statistics. */ |
| 494 | q->buffer_used += roundup(skb->len + hdrlen, 4); |
| 495 | q->free_packet_slots -= 1; |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 500 | int b43_pio_tx(struct b43_wldev *dev, struct sk_buff *skb) |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 501 | { |
| 502 | struct b43_pio_txqueue *q; |
| 503 | struct ieee80211_hdr *hdr; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 504 | unsigned int hdrlen, total_len; |
| 505 | int err = 0; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 506 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 507 | |
| 508 | hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 509 | |
| 510 | if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 511 | /* The multicast queue will be sent after the DTIM. */ |
| 512 | q = dev->pio.tx_queue_mcast; |
| 513 | /* Set the frame More-Data bit. Ucode will clear it |
| 514 | * for us on the last frame. */ |
| 515 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 516 | } else { |
| 517 | /* Decide by priority where to put this frame. */ |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 518 | q = select_queue_by_priority(dev, skb_get_queue_mapping(skb)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 519 | } |
| 520 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 521 | hdrlen = b43_txhdr_size(dev); |
| 522 | total_len = roundup(skb->len + hdrlen, 4); |
| 523 | |
| 524 | if (unlikely(total_len > q->buffer_size)) { |
| 525 | err = -ENOBUFS; |
| 526 | b43dbg(dev->wl, "PIO: TX packet longer than queue.\n"); |
Michael Buesch | 637dae3 | 2009-09-04 22:55:00 +0200 | [diff] [blame] | 527 | goto out; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 528 | } |
| 529 | if (unlikely(q->free_packet_slots == 0)) { |
| 530 | err = -ENOBUFS; |
| 531 | b43warn(dev->wl, "PIO: TX packet overflow.\n"); |
Michael Buesch | 637dae3 | 2009-09-04 22:55:00 +0200 | [diff] [blame] | 532 | goto out; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 533 | } |
| 534 | B43_WARN_ON(q->buffer_used > q->buffer_size); |
| 535 | |
| 536 | if (total_len > (q->buffer_size - q->buffer_used)) { |
| 537 | /* Not enough memory on the queue. */ |
| 538 | err = -EBUSY; |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 539 | ieee80211_stop_queue(dev->wl->hw, skb_get_queue_mapping(skb)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 540 | q->stopped = 1; |
Michael Buesch | 637dae3 | 2009-09-04 22:55:00 +0200 | [diff] [blame] | 541 | goto out; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /* Assign the queue number to the ring (if not already done before) |
| 545 | * so TX status handling can use it. The mac80211-queue to b43-queue |
| 546 | * mapping is static, so we don't need to store it per frame. */ |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 547 | q->queue_prio = skb_get_queue_mapping(skb); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 548 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 549 | err = pio_tx_frame(q, skb); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 550 | if (unlikely(err == -ENOKEY)) { |
| 551 | /* Drop this packet, as we don't have the encryption key |
| 552 | * anymore and must not transmit it unencrypted. */ |
| 553 | dev_kfree_skb_any(skb); |
| 554 | err = 0; |
Michael Buesch | 637dae3 | 2009-09-04 22:55:00 +0200 | [diff] [blame] | 555 | goto out; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 556 | } |
| 557 | if (unlikely(err)) { |
| 558 | b43err(dev->wl, "PIO transmission failure\n"); |
Michael Buesch | 637dae3 | 2009-09-04 22:55:00 +0200 | [diff] [blame] | 559 | goto out; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 560 | } |
| 561 | q->nr_tx_packets++; |
| 562 | |
| 563 | B43_WARN_ON(q->buffer_used > q->buffer_size); |
| 564 | if (((q->buffer_size - q->buffer_used) < roundup(2 + 2 + 6, 4)) || |
| 565 | (q->free_packet_slots == 0)) { |
| 566 | /* The queue is full. */ |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 567 | ieee80211_stop_queue(dev->wl->hw, skb_get_queue_mapping(skb)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 568 | q->stopped = 1; |
| 569 | } |
| 570 | |
Michael Buesch | 637dae3 | 2009-09-04 22:55:00 +0200 | [diff] [blame] | 571 | out: |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 572 | return err; |
| 573 | } |
| 574 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 575 | void b43_pio_handle_txstatus(struct b43_wldev *dev, |
| 576 | const struct b43_txstatus *status) |
| 577 | { |
| 578 | struct b43_pio_txqueue *q; |
| 579 | struct b43_pio_txpacket *pack = NULL; |
| 580 | unsigned int total_len; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 581 | struct ieee80211_tx_info *info; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 582 | |
| 583 | q = parse_cookie(dev, status->cookie, &pack); |
| 584 | if (unlikely(!q)) |
| 585 | return; |
| 586 | B43_WARN_ON(!pack); |
| 587 | |
Michael Buesch | 14a7dd6 | 2008-06-24 12:22:05 +0200 | [diff] [blame] | 588 | info = IEEE80211_SKB_CB(pack->skb); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 589 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 590 | b43_fill_txstatus_report(dev, info, status); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 591 | |
| 592 | total_len = pack->skb->len + b43_txhdr_size(dev); |
| 593 | total_len = roundup(total_len, 4); |
| 594 | q->buffer_used -= total_len; |
| 595 | q->free_packet_slots += 1; |
| 596 | |
Michael Buesch | ce6c4a1 | 2009-09-10 20:22:02 +0200 | [diff] [blame] | 597 | ieee80211_tx_status(dev->wl->hw, pack->skb); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 598 | pack->skb = NULL; |
| 599 | list_add(&pack->list, &q->packets_list); |
| 600 | |
| 601 | if (q->stopped) { |
| 602 | ieee80211_wake_queue(dev->wl->hw, q->queue_prio); |
| 603 | q->stopped = 0; |
| 604 | } |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | void b43_pio_get_tx_stats(struct b43_wldev *dev, |
| 608 | struct ieee80211_tx_queue_stats *stats) |
| 609 | { |
| 610 | const int nr_queues = dev->wl->hw->queues; |
| 611 | struct b43_pio_txqueue *q; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 612 | int i; |
| 613 | |
| 614 | for (i = 0; i < nr_queues; i++) { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 615 | q = select_queue_by_priority(dev, i); |
| 616 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 617 | stats[i].len = B43_PIO_MAX_NR_TXPACKETS - q->free_packet_slots; |
| 618 | stats[i].limit = B43_PIO_MAX_NR_TXPACKETS; |
| 619 | stats[i].count = q->nr_tx_packets; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | /* Returns whether we should fetch another frame. */ |
| 624 | static bool pio_rx_frame(struct b43_pio_rxqueue *q) |
| 625 | { |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 626 | struct b43_wldev *dev = q->dev; |
Albert Herranz | 7e937c6 | 2009-10-07 00:07:44 +0200 | [diff] [blame] | 627 | struct b43_wl *wl = dev->wl; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 628 | u16 len; |
| 629 | u32 macstat; |
| 630 | unsigned int i, padding; |
| 631 | struct sk_buff *skb; |
| 632 | const char *err_msg = NULL; |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 633 | struct b43_rxhdr_fw4 *rxhdr = |
| 634 | (struct b43_rxhdr_fw4 *)wl->pio_scratchspace; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 635 | |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 636 | BUILD_BUG_ON(sizeof(wl->pio_scratchspace) < sizeof(*rxhdr)); |
| 637 | memset(rxhdr, 0, sizeof(*rxhdr)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 638 | |
| 639 | /* Check if we have data and wait for it to get ready. */ |
| 640 | if (q->rev >= 8) { |
| 641 | u32 ctl; |
| 642 | |
| 643 | ctl = b43_piorx_read32(q, B43_PIO8_RXCTL); |
| 644 | if (!(ctl & B43_PIO8_RXCTL_FRAMERDY)) |
| 645 | return 0; |
| 646 | b43_piorx_write32(q, B43_PIO8_RXCTL, |
| 647 | B43_PIO8_RXCTL_FRAMERDY); |
| 648 | for (i = 0; i < 10; i++) { |
| 649 | ctl = b43_piorx_read32(q, B43_PIO8_RXCTL); |
| 650 | if (ctl & B43_PIO8_RXCTL_DATARDY) |
| 651 | goto data_ready; |
| 652 | udelay(10); |
| 653 | } |
| 654 | } else { |
| 655 | u16 ctl; |
| 656 | |
| 657 | ctl = b43_piorx_read16(q, B43_PIO_RXCTL); |
| 658 | if (!(ctl & B43_PIO_RXCTL_FRAMERDY)) |
| 659 | return 0; |
| 660 | b43_piorx_write16(q, B43_PIO_RXCTL, |
| 661 | B43_PIO_RXCTL_FRAMERDY); |
| 662 | for (i = 0; i < 10; i++) { |
| 663 | ctl = b43_piorx_read16(q, B43_PIO_RXCTL); |
| 664 | if (ctl & B43_PIO_RXCTL_DATARDY) |
| 665 | goto data_ready; |
| 666 | udelay(10); |
| 667 | } |
| 668 | } |
| 669 | b43dbg(q->dev->wl, "PIO RX timed out\n"); |
| 670 | return 1; |
| 671 | data_ready: |
| 672 | |
| 673 | /* Get the preamble (RX header) */ |
| 674 | if (q->rev >= 8) { |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 675 | ssb_block_read(dev->dev, rxhdr, sizeof(*rxhdr), |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 676 | q->mmio_base + B43_PIO8_RXDATA, |
| 677 | sizeof(u32)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 678 | } else { |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 679 | ssb_block_read(dev->dev, rxhdr, sizeof(*rxhdr), |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 680 | q->mmio_base + B43_PIO_RXDATA, |
| 681 | sizeof(u16)); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 682 | } |
| 683 | /* Sanity checks. */ |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 684 | len = le16_to_cpu(rxhdr->frame_len); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 685 | if (unlikely(len > 0x700)) { |
| 686 | err_msg = "len > 0x700"; |
| 687 | goto rx_error; |
| 688 | } |
| 689 | if (unlikely(len == 0)) { |
| 690 | err_msg = "len == 0"; |
| 691 | goto rx_error; |
| 692 | } |
| 693 | |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 694 | macstat = le32_to_cpu(rxhdr->mac_status); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 695 | if (macstat & B43_RX_MAC_FCSERR) { |
| 696 | if (!(q->dev->wl->filter_flags & FIF_FCSFAIL)) { |
| 697 | /* Drop frames with failed FCS. */ |
| 698 | err_msg = "Frame FCS error"; |
| 699 | goto rx_error; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | /* We always pad 2 bytes, as that's what upstream code expects |
| 704 | * due to the RX-header being 30 bytes. In case the frame is |
| 705 | * unaligned, we pad another 2 bytes. */ |
| 706 | padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0; |
| 707 | skb = dev_alloc_skb(len + padding + 2); |
| 708 | if (unlikely(!skb)) { |
| 709 | err_msg = "Out of memory"; |
| 710 | goto rx_error; |
| 711 | } |
| 712 | skb_reserve(skb, 2); |
| 713 | skb_put(skb, len + padding); |
| 714 | if (q->rev >= 8) { |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 715 | ssb_block_read(dev->dev, skb->data + padding, (len & ~3), |
| 716 | q->mmio_base + B43_PIO8_RXDATA, |
| 717 | sizeof(u32)); |
| 718 | if (len & 3) { |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 719 | u8 *tail = wl->pio_tailspace; |
| 720 | BUILD_BUG_ON(sizeof(wl->pio_tailspace) < 4); |
| 721 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 722 | /* Read the last few bytes. */ |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 723 | ssb_block_read(dev->dev, tail, 4, |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 724 | q->mmio_base + B43_PIO8_RXDATA, |
| 725 | sizeof(u32)); |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 726 | switch (len & 3) { |
| 727 | case 3: |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 728 | skb->data[len + padding - 3] = tail[0]; |
| 729 | skb->data[len + padding - 2] = tail[1]; |
| 730 | skb->data[len + padding - 1] = tail[2]; |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 731 | break; |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 732 | case 2: |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 733 | skb->data[len + padding - 2] = tail[0]; |
| 734 | skb->data[len + padding - 1] = tail[1]; |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 735 | break; |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 736 | case 1: |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 737 | skb->data[len + padding - 1] = tail[0]; |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 738 | break; |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 739 | } |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 740 | } |
| 741 | } else { |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 742 | ssb_block_read(dev->dev, skb->data + padding, (len & ~1), |
| 743 | q->mmio_base + B43_PIO_RXDATA, |
| 744 | sizeof(u16)); |
| 745 | if (len & 1) { |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 746 | u8 *tail = wl->pio_tailspace; |
| 747 | BUILD_BUG_ON(sizeof(wl->pio_tailspace) < 2); |
| 748 | |
Michael Buesch | d8c17e1 | 2008-04-02 19:58:20 +0200 | [diff] [blame] | 749 | /* Read the last byte. */ |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 750 | ssb_block_read(dev->dev, tail, 2, |
Michael Buesch | b96ab54 | 2009-09-23 18:51:21 +0200 | [diff] [blame] | 751 | q->mmio_base + B43_PIO_RXDATA, |
| 752 | sizeof(u16)); |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 753 | skb->data[len + padding - 1] = tail[0]; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 757 | b43_rx(q->dev, skb, rxhdr); |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 758 | |
| 759 | return 1; |
| 760 | |
| 761 | rx_error: |
| 762 | if (err_msg) |
| 763 | b43dbg(q->dev->wl, "PIO RX error: %s\n", err_msg); |
Michael Buesch | c286181 | 2009-11-07 18:54:22 +0100 | [diff] [blame^] | 764 | if (q->rev >= 8) |
| 765 | b43_piorx_write32(q, B43_PIO8_RXCTL, B43_PIO8_RXCTL_DATARDY); |
| 766 | else |
| 767 | b43_piorx_write16(q, B43_PIO_RXCTL, B43_PIO_RXCTL_DATARDY); |
| 768 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 769 | return 1; |
| 770 | } |
| 771 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 772 | void b43_pio_rx(struct b43_pio_rxqueue *q) |
| 773 | { |
Michael Buesch | 77ca07f | 2009-09-04 22:56:19 +0200 | [diff] [blame] | 774 | unsigned int count = 0; |
| 775 | bool stop; |
| 776 | |
| 777 | while (1) { |
| 778 | stop = (pio_rx_frame(q) == 0); |
| 779 | if (stop) |
| 780 | break; |
| 781 | cond_resched(); |
| 782 | if (WARN_ON_ONCE(++count > 10000)) |
| 783 | break; |
| 784 | } |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | static void b43_pio_tx_suspend_queue(struct b43_pio_txqueue *q) |
| 788 | { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 789 | if (q->rev >= 8) { |
| 790 | b43_piotx_write32(q, B43_PIO8_TXCTL, |
| 791 | b43_piotx_read32(q, B43_PIO8_TXCTL) |
| 792 | | B43_PIO8_TXCTL_SUSPREQ); |
| 793 | } else { |
| 794 | b43_piotx_write16(q, B43_PIO_TXCTL, |
| 795 | b43_piotx_read16(q, B43_PIO_TXCTL) |
| 796 | | B43_PIO_TXCTL_SUSPREQ); |
| 797 | } |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | static void b43_pio_tx_resume_queue(struct b43_pio_txqueue *q) |
| 801 | { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 802 | if (q->rev >= 8) { |
| 803 | b43_piotx_write32(q, B43_PIO8_TXCTL, |
| 804 | b43_piotx_read32(q, B43_PIO8_TXCTL) |
| 805 | & ~B43_PIO8_TXCTL_SUSPREQ); |
| 806 | } else { |
| 807 | b43_piotx_write16(q, B43_PIO_TXCTL, |
| 808 | b43_piotx_read16(q, B43_PIO_TXCTL) |
| 809 | & ~B43_PIO_TXCTL_SUSPREQ); |
| 810 | } |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | void b43_pio_tx_suspend(struct b43_wldev *dev) |
| 814 | { |
| 815 | b43_power_saving_ctl_bits(dev, B43_PS_AWAKE); |
| 816 | b43_pio_tx_suspend_queue(dev->pio.tx_queue_AC_BK); |
| 817 | b43_pio_tx_suspend_queue(dev->pio.tx_queue_AC_BE); |
| 818 | b43_pio_tx_suspend_queue(dev->pio.tx_queue_AC_VI); |
| 819 | b43_pio_tx_suspend_queue(dev->pio.tx_queue_AC_VO); |
| 820 | b43_pio_tx_suspend_queue(dev->pio.tx_queue_mcast); |
| 821 | } |
| 822 | |
| 823 | void b43_pio_tx_resume(struct b43_wldev *dev) |
| 824 | { |
| 825 | b43_pio_tx_resume_queue(dev->pio.tx_queue_mcast); |
| 826 | b43_pio_tx_resume_queue(dev->pio.tx_queue_AC_VO); |
| 827 | b43_pio_tx_resume_queue(dev->pio.tx_queue_AC_VI); |
| 828 | b43_pio_tx_resume_queue(dev->pio.tx_queue_AC_BE); |
| 829 | b43_pio_tx_resume_queue(dev->pio.tx_queue_AC_BK); |
| 830 | b43_power_saving_ctl_bits(dev, 0); |
| 831 | } |