📄 pio.c
字号:
/* Broadcom B43legacy wireless driver PIO Transmission Copyright (c) 2005 Michael Buesch <mb@bu3sch.de> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.*/#include "b43legacy.h"#include "pio.h"#include "main.h"#include "xmit.h"#include <linux/delay.h>static void tx_start(struct b43legacy_pioqueue *queue){ b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, B43legacy_PIO_TXCTL_INIT);}static void tx_octet(struct b43legacy_pioqueue *queue, u8 octet){ if (queue->need_workarounds) { b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, octet); b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, B43legacy_PIO_TXCTL_WRITELO); } else { b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, B43legacy_PIO_TXCTL_WRITELO); b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, octet); }}static u16 tx_get_next_word(const u8 *txhdr, const u8 *packet, size_t txhdr_size, unsigned int *pos){ const u8 *source; unsigned int i = *pos; u16 ret; if (i < txhdr_size) source = txhdr; else { source = packet; i -= txhdr_size; } ret = le16_to_cpu(*((__le16 *)(source + i))); *pos += 2; return ret;}static void tx_data(struct b43legacy_pioqueue *queue, u8 *txhdr, const u8 *packet, unsigned int octets){ u16 data; unsigned int i = 0; if (queue->need_workarounds) { data = tx_get_next_word(txhdr, packet, sizeof(struct b43legacy_txhdr_fw3), &i); b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, data); } b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, B43legacy_PIO_TXCTL_WRITELO | B43legacy_PIO_TXCTL_WRITEHI); while (i < octets - 1) { data = tx_get_next_word(txhdr, packet, sizeof(struct b43legacy_txhdr_fw3), &i); b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, data); } if (octets % 2) tx_octet(queue, packet[octets - sizeof(struct b43legacy_txhdr_fw3) - 1]);}static void tx_complete(struct b43legacy_pioqueue *queue, struct sk_buff *skb){ if (queue->need_workarounds) { b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, skb->data[skb->len - 1]); b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, B43legacy_PIO_TXCTL_WRITELO | B43legacy_PIO_TXCTL_COMPLETE); } else b43legacy_pio_write(queue, B43legacy_PIO_TXCTL, B43legacy_PIO_TXCTL_COMPLETE);}static u16 generate_cookie(struct b43legacy_pioqueue *queue, struct b43legacy_pio_txpacket *packet){ u16 cookie = 0x0000; int packetindex; /* We use the upper 4 bits for the PIO * controller ID and the lower 12 bits * for the packet index (in the cache). */ switch (queue->mmio_base) { case B43legacy_MMIO_PIO1_BASE: break; case B43legacy_MMIO_PIO2_BASE: cookie = 0x1000; break; case B43legacy_MMIO_PIO3_BASE: cookie = 0x2000; break; case B43legacy_MMIO_PIO4_BASE: cookie = 0x3000; break; default: B43legacy_WARN_ON(1); } packetindex = pio_txpacket_getindex(packet); B43legacy_WARN_ON(!(((u16)packetindex & 0xF000) == 0x0000)); cookie |= (u16)packetindex; return cookie;}staticstruct b43legacy_pioqueue *parse_cookie(struct b43legacy_wldev *dev, u16 cookie, struct b43legacy_pio_txpacket **packet){ struct b43legacy_pio *pio = &dev->pio; struct b43legacy_pioqueue *queue = NULL; int packetindex; switch (cookie & 0xF000) { case 0x0000: queue = pio->queue0; break; case 0x1000: queue = pio->queue1; break; case 0x2000: queue = pio->queue2; break; case 0x3000: queue = pio->queue3; break; default: B43legacy_WARN_ON(1); } packetindex = (cookie & 0x0FFF); B43legacy_WARN_ON(!(packetindex >= 0 && packetindex < B43legacy_PIO_MAXTXPACKETS)); *packet = &(queue->tx_packets_cache[packetindex]); return queue;}union txhdr_union { struct b43legacy_txhdr_fw3 txhdr_fw3;};static int pio_tx_write_fragment(struct b43legacy_pioqueue *queue, struct sk_buff *skb, struct b43legacy_pio_txpacket *packet, size_t txhdr_size){ union txhdr_union txhdr_data; u8 *txhdr = NULL; unsigned int octets; int err; txhdr = (u8 *)(&txhdr_data.txhdr_fw3); B43legacy_WARN_ON(skb_shinfo(skb)->nr_frags != 0); err = b43legacy_generate_txhdr(queue->dev, txhdr, skb->data, skb->len, &packet->txstat.control, generate_cookie(queue, packet)); if (err) return err; tx_start(queue); octets = skb->len + txhdr_size; if (queue->need_workarounds) octets--; tx_data(queue, txhdr, (u8 *)skb->data, octets); tx_complete(queue, skb); return 0;}static void free_txpacket(struct b43legacy_pio_txpacket *packet, int irq_context){ struct b43legacy_pioqueue *queue = packet->queue; if (packet->skb) { if (irq_context) dev_kfree_skb_irq(packet->skb); else dev_kfree_skb(packet->skb); } list_move(&packet->list, &queue->txfree); queue->nr_txfree++;}static int pio_tx_packet(struct b43legacy_pio_txpacket *packet){ struct b43legacy_pioqueue *queue = packet->queue; struct sk_buff *skb = packet->skb; u16 octets; int err; octets = (u16)skb->len + sizeof(struct b43legacy_txhdr_fw3); if (queue->tx_devq_size < octets) { b43legacywarn(queue->dev->wl, "PIO queue too small. " "Dropping packet.\n"); /* Drop it silently (return success) */ free_txpacket(packet, 1); return 0; } B43legacy_WARN_ON(queue->tx_devq_packets > B43legacy_PIO_MAXTXDEVQPACKETS); B43legacy_WARN_ON(queue->tx_devq_used > queue->tx_devq_size); /* Check if there is sufficient free space on the device * TX queue. If not, return and let the TX tasklet * retry later. */ if (queue->tx_devq_packets == B43legacy_PIO_MAXTXDEVQPACKETS) return -EBUSY; if (queue->tx_devq_used + octets > queue->tx_devq_size) return -EBUSY; /* Now poke the device. */ err = pio_tx_write_fragment(queue, skb, packet, sizeof(struct b43legacy_txhdr_fw3)); if (unlikely(err == -ENOKEY)) { /* Drop this packet, as we don't have the encryption key * anymore and must not transmit it unencrypted. */ free_txpacket(packet, 1); return 0; } /* Account for the packet size. * (We must not overflow the device TX queue) */ queue->tx_devq_packets++; queue->tx_devq_used += octets; /* Transmission started, everything ok, move the * packet to the txrunning list. */ list_move_tail(&packet->list, &queue->txrunning); return 0;}static void tx_tasklet(unsigned long d){ struct b43legacy_pioqueue *queue = (struct b43legacy_pioqueue *)d; struct b43legacy_wldev *dev = queue->dev; unsigned long flags; struct b43legacy_pio_txpacket *packet, *tmp_packet; int err; u16 txctl; spin_lock_irqsave(&dev->wl->irq_lock, flags); if (queue->tx_frozen) goto out_unlock; txctl = b43legacy_pio_read(queue, B43legacy_PIO_TXCTL); if (txctl & B43legacy_PIO_TXCTL_SUSPEND) goto out_unlock; list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) { /* Try to transmit the packet. This can fail, if * the device queue is full. In case of failure, the * packet is left in the txqueue. * If transmission succeed, the packet is moved to txrunning. * If it is impossible to transmit the packet, it * is dropped. */ err = pio_tx_packet(packet); if (err) break; }out_unlock: spin_unlock_irqrestore(&dev->wl->irq_lock, flags);}static void setup_txqueues(struct b43legacy_pioqueue *queue){ struct b43legacy_pio_txpacket *packet; int i; queue->nr_txfree = B43legacy_PIO_MAXTXPACKETS; for (i = 0; i < B43legacy_PIO_MAXTXPACKETS; i++) { packet = &(queue->tx_packets_cache[i]); packet->queue = queue; INIT_LIST_HEAD(&packet->list); list_add(&packet->list, &queue->txfree); }}staticstruct b43legacy_pioqueue *b43legacy_setup_pioqueue(struct b43legacy_wldev *dev, u16 pio_mmio_base){ struct b43legacy_pioqueue *queue; u32 value; u16 qsize; queue = kzalloc(sizeof(*queue), GFP_KERNEL); if (!queue) goto out; queue->dev = dev; queue->mmio_base = pio_mmio_base; queue->need_workarounds = (dev->dev->id.revision < 3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -