⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pio.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  Broadcom B43 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 "b43.h"#include "pio.h"#include "main.h"#include "xmit.h"#include <linux/delay.h>static void tx_start(struct b43_pioqueue *queue){	b43_pio_write(queue, B43_PIO_TXCTL, B43_PIO_TXCTL_INIT);}static void tx_octet(struct b43_pioqueue *queue, u8 octet){	if (queue->need_workarounds) {		b43_pio_write(queue, B43_PIO_TXDATA, octet);		b43_pio_write(queue, B43_PIO_TXCTL, B43_PIO_TXCTL_WRITELO);	} else {		b43_pio_write(queue, B43_PIO_TXCTL, B43_PIO_TXCTL_WRITELO);		b43_pio_write(queue, B43_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 b43_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 b43_txhdr_fw4), &i);		b43_pio_write(queue, B43_PIO_TXDATA, data);	}	b43_pio_write(queue, B43_PIO_TXCTL,		      B43_PIO_TXCTL_WRITELO | B43_PIO_TXCTL_WRITEHI);	while (i < octets - 1) {		data = tx_get_next_word(txhdr, packet,					sizeof(struct b43_txhdr_fw4), &i);		b43_pio_write(queue, B43_PIO_TXDATA, data);	}	if (octets % 2)		tx_octet(queue,			 packet[octets - sizeof(struct b43_txhdr_fw4) - 1]);}static void tx_complete(struct b43_pioqueue *queue, struct sk_buff *skb){	if (queue->need_workarounds) {		b43_pio_write(queue, B43_PIO_TXDATA, skb->data[skb->len - 1]);		b43_pio_write(queue, B43_PIO_TXCTL,			      B43_PIO_TXCTL_WRITELO | B43_PIO_TXCTL_COMPLETE);	} else {		b43_pio_write(queue, B43_PIO_TXCTL, B43_PIO_TXCTL_COMPLETE);	}}static u16 generate_cookie(struct b43_pioqueue *queue,			   struct b43_pio_txpacket *packet){	u16 cookie = 0x0000;	u16 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 B43_MMIO_PIO1_BASE:		break;	case B43_MMIO_PIO2_BASE:		cookie = 0x1000;		break;	case B43_MMIO_PIO3_BASE:		cookie = 0x2000;		break;	case B43_MMIO_PIO4_BASE:		cookie = 0x3000;		break;	default:		B43_WARN_ON(1);	}	packetindex = packet->index;	B43_WARN_ON(packetindex & ~0x0FFF);	cookie |= (u16) packetindex;	return cookie;}staticstruct b43_pioqueue *parse_cookie(struct b43_wldev *dev,				  u16 cookie, struct b43_pio_txpacket **packet){	struct b43_pio *pio = &dev->pio;	struct b43_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:		B43_WARN_ON(1);	}	packetindex = (cookie & 0x0FFF);	B43_WARN_ON(!(packetindex >= 0 && packetindex < B43_PIO_MAXTXPACKETS));	*packet = &(queue->tx_packets_cache[packetindex]);	return queue;}union txhdr_union {	struct b43_txhdr_fw4 txhdr_fw4;};static void pio_tx_write_fragment(struct b43_pioqueue *queue,				  struct sk_buff *skb,				  struct b43_pio_txpacket *packet,				  size_t txhdr_size){	union txhdr_union txhdr_data;	u8 *txhdr = NULL;	unsigned int octets;	txhdr = (u8 *) (&txhdr_data.txhdr_fw4);	B43_WARN_ON(skb_shinfo(skb)->nr_frags);	b43_generate_txhdr(queue->dev,			   txhdr, skb->data, skb->len,			   &packet->txstat.control,			   generate_cookie(queue, packet));	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);}static void free_txpacket(struct b43_pio_txpacket *packet){	struct b43_pioqueue *queue = packet->queue;	if (packet->skb)		dev_kfree_skb_any(packet->skb);	list_move(&packet->list, &queue->txfree);	queue->nr_txfree++;}static int pio_tx_packet(struct b43_pio_txpacket *packet){	struct b43_pioqueue *queue = packet->queue;	struct sk_buff *skb = packet->skb;	u16 octets;	octets = (u16) skb->len + sizeof(struct b43_txhdr_fw4);	if (queue->tx_devq_size < octets) {		b43warn(queue->dev->wl, "PIO queue too small. "			"Dropping packet.\n");		/* Drop it silently (return success) */		free_txpacket(packet);		return 0;	}	B43_WARN_ON(queue->tx_devq_packets > B43_PIO_MAXTXDEVQPACKETS);	B43_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 == B43_PIO_MAXTXDEVQPACKETS)		return -EBUSY;	if (queue->tx_devq_used + octets > queue->tx_devq_size)		return -EBUSY;	/* Now poke the device. */	pio_tx_write_fragment(queue, skb, packet, sizeof(struct b43_txhdr_fw4));	/* 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 b43_pioqueue *queue = (struct b43_pioqueue *)d;	struct b43_wldev *dev = queue->dev;	unsigned long flags;	struct b43_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 = b43_pio_read(queue, B43_PIO_TXCTL);	if (txctl & B43_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 b43_pioqueue *queue){	struct b43_pio_txpacket *packet;	int i;	queue->nr_txfree = B43_PIO_MAXTXPACKETS;	for (i = 0; i < B43_PIO_MAXTXPACKETS; i++) {		packet = &(queue->tx_packets_cache[i]);		packet->queue = queue;		INIT_LIST_HEAD(&packet->list);		packet->index = i;		list_add(&packet->list, &queue->txfree);	}}staticstruct b43_pioqueue *b43_setup_pioqueue(struct b43_wldev *dev,					u16 pio_mmio_base){	struct b43_pioqueue *queue;	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);	INIT_LIST_HEAD(&queue->txfree);	INIT_LIST_HEAD(&queue->txqueue);	INIT_LIST_HEAD(&queue->txrunning);	tasklet_init(&queue->txtask, tx_tasklet, (unsigned long)queue);	b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)		    & ~B43_MACCTL_BE);	qsize = b43_read16(dev, queue->mmio_base + B43_PIO_TXQBUFSIZE);	if (qsize == 0) {		b43err(dev->wl, "This card does not support PIO "		       "operation mode. Please use DMA mode "		       "(module parameter pio=0).\n");		goto err_freequeue;	}	if (qsize <= B43_PIO_TXQADJUST) {		b43err(dev->wl, "PIO tx device-queue too small (%u)\n", qsize);		goto err_freequeue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -