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

📄 yellowfin.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 4 页
字号:
/* yellowfin.c: A Packet Engines G-NIC ethernet driver for linux. *//*	Written 1997-2001 by Donald Becker.	This software may be used and distributed according to the terms of	the GNU General Public License (GPL), incorporated herein by reference.	Drivers based on or derived from this code fall under the GPL and must	retain the authorship, copyright and license notice.  This file is not	a complete program and may only be used when the entire operating	system is licensed under the GPL.	This driver is for the Packet Engines G-NIC PCI Gigabit Ethernet adapter.	It also supports the Symbios Logic version of the same chip core.	The author may be reached as becker@scyld.com, or C/O	Scyld Computing Corporation	410 Severn Ave., Suite 210	Annapolis MD 21403	Support and updates available at	http://www.scyld.com/network/yellowfin.html	Linux kernel changelog:	-----------------------	LK1.1.1 (jgarzik): Port to 2.4 kernel	LK1.1.2 (jgarzik):	* Merge in becker version 1.05	LK1.1.3 (jgarzik):	* Various cleanups	* Update yellowfin_timer to correctly calculate duplex.	(suggested by Manfred Spraul)	LK1.1.4 (val@nmt.edu):	* Fix three endian-ness bugs	* Support dual function SYM53C885E ethernet chip		LK1.1.5 (val@nmt.edu):	* Fix forced full-duplex bug I introduced	*/#define DRV_NAME	"yellowfin"#define DRV_VERSION	"1.05+LK1.1.5"#define DRV_RELDATE	"May 10, 2001"#define PFX DRV_NAME ": "/* The user-configurable values.   These may be modified when a driver module is loaded.*/static int debug = 1;			/* 1 normal messages, 0 quiet .. 7 verbose. *//* Maximum events (Rx packets, etc.) to handle at each interrupt. */static int max_interrupt_work = 20;static int mtu;#ifdef YF_PROTOTYPE			/* Support for prototype hardware errata. *//* System-wide count of bogus-rx frames. */static int bogus_rx;static int dma_ctrl = 0x004A0263; 			/* Constrained by errata */static int fifo_cfg = 0x0020;				/* Bypass external Tx FIFO. */#elif YF_NEW					/* A future perfect board :->.  */static int dma_ctrl = 0x00CAC277;			/* Override when loading module! */static int fifo_cfg = 0x0028;#elsestatic int dma_ctrl = 0x004A0263; 			/* Constrained by errata */static int fifo_cfg = 0x0020;				/* Bypass external Tx FIFO. */#endif/* Set the copy breakpoint for the copy-only-tiny-frames scheme.   Setting to > 1514 effectively disables this feature. */static int rx_copybreak;/* Used to pass the media type, etc.   No media types are currently defined.  These exist for driver   interoperability.*/#define MAX_UNITS 8				/* More are supported, limit only on options */static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};/* Do ugly workaround for GX server chipset errata. */static int gx_fix;/* Operational parameters that are set at compile time. *//* Keep the ring sizes a power of two for efficiency.   Making the Tx ring too long decreases the effectiveness of channel   bonding and packet priority.   There are no ill effects from too-large receive rings. */#define TX_RING_SIZE	16#define TX_QUEUE_SIZE	12		/* Must be > 4 && <= TX_RING_SIZE */#define RX_RING_SIZE	64#define STATUS_TOTAL_SIZE	TX_RING_SIZE*sizeof(struct tx_status_words)#define TX_TOTAL_SIZE		2*TX_RING_SIZE*sizeof(struct yellowfin_desc)#define RX_TOTAL_SIZE		RX_RING_SIZE*sizeof(struct yellowfin_desc)/* Operational parameters that usually are not changed. *//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT  (2*HZ)#define PKT_BUF_SZ		1536			/* Size of each temporary Rx buffer.*/#define yellowfin_debug debug#if !defined(__OPTIMIZE__)#warning  You must compile this file with the correct options!#warning  See the last lines of the source file.#error You must compile this driver with "-O".#endif#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/mii.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/ethtool.h>#include <asm/uaccess.h>#include <asm/processor.h>		/* Processor type for cache alignment. */#include <asm/unaligned.h>#include <asm/bitops.h>#include <asm/io.h>/* These identify the driver base version and may not be removed. */static char version[] __devinitdata =KERN_INFO DRV_NAME ".c:v1.05  1/09/2001  Written by Donald Becker <becker@scyld.com>\n"KERN_INFO "  http://www.scyld.com/network/yellowfin.html\n"KERN_INFO "  (unofficial 2.4.x port, " DRV_VERSION ", " DRV_RELDATE ")\n";#ifndef USE_IO_OPS#undef inb#undef inw#undef inl#undef outb#undef outw#undef outl#define inb readb#define inw readw#define inl readl#define outb writeb#define outw writew#define outl writel#endif /* !USE_IO_OPS */MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("Packet Engines Yellowfin G-NIC Gigabit Ethernet driver");MODULE_LICENSE("GPL");MODULE_PARM(max_interrupt_work, "i");MODULE_PARM(mtu, "i");MODULE_PARM(debug, "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(gx_fix, "i");MODULE_PARM_DESC(max_interrupt_work, "G-NIC maximum events handled per interrupt");MODULE_PARM_DESC(mtu, "G-NIC MTU (all boards)");MODULE_PARM_DESC(debug, "G-NIC debug level (0-7)");MODULE_PARM_DESC(rx_copybreak, "G-NIC copy breakpoint for copy-only-tiny-frames");MODULE_PARM_DESC(options, "G-NIC: Bits 0-3: media type, bit 17: full duplex");MODULE_PARM_DESC(full_duplex, "G-NIC full duplex setting(s) (1)");MODULE_PARM_DESC(gx_fix, "G-NIC: enable GX server chipset bug workaround (0-1)");/*				Theory of OperationI. Board CompatibilityThis device driver is designed for the Packet Engines "Yellowfin" GigabitEthernet adapter.  The only PCA currently supported is the G-NIC 64-bitPCI card.II. Board-specific settingsPCI bus devices are configured by the system at boot time, so no jumpersneed to be set on the board.  The system BIOS preferably should assign thePCI INTA signal to an otherwise unused system IRQ line.Note: Kernel versions earlier than 1.3.73 do not support shared PCIinterrupt lines.III. Driver operationIIIa. Ring buffersThe Yellowfin uses the Descriptor Based DMA Architecture specified by Apple.This is a descriptor list scheme similar to that used by the EEPro100 andTulip.  This driver uses two statically allocated fixed-size descriptor listsformed into rings by a branch from the final descriptor to the beginning ofthe list.  The ring sizes are set at compile time by RX/TX_RING_SIZE.The driver allocates full frame size skbuffs for the Rx ring buffers atopen() time and passes the skb->data field to the Yellowfin as receive databuffers.  When an incoming frame is less than RX_COPYBREAK bytes long,a fresh skbuff is allocated and the frame is copied to the new skbuff.When the incoming frame is larger, the skbuff is passed directly up theprotocol stack and replaced by a newly allocated skbuff.The RX_COPYBREAK value is chosen to trade-off the memory wasted byusing a full-sized skbuff for small frames vs. the copying costs of largerframes.  For small frames the copying cost is negligible (esp. consideringthat we are pre-loading the cache with immediately useful headerinformation).  For large frames the copying cost is non-trivial, and thelarger copy might flush the cache of useful data.IIIC. SynchronizationThe driver runs as two independent, single-threaded flows of control.  Oneis the send-packet routine, which enforces single-threaded use by thedev->tbusy flag.  The other thread is the interrupt handler, which is singlethreaded by the hardware and other software.The send packet thread has partial control over the Tx ring and 'dev->tbusy'flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the nextqueue slot is empty, it clears the tbusy flag when finished otherwise it setsthe 'yp->tx_full' flag.The interrupt handler has exclusive control over the Rx ring and records statsfrom the Tx ring.  After reaping the stats, it marks the Tx queue entry asempty by incrementing the dirty_tx mark. Iff the 'yp->tx_full' flag is set, itclears both the tx_full and tbusy flags.IV. NotesThanks to Kim Stearns of Packet Engines for providing a pair of G-NIC boards.Thanks to Bruce Faust of Digitalscape for providing both their SYM53C885 boardand an AlphaStation to verifty the Alpha port!IVb. ReferencesYellowfin Engineering Design Specification, 4/23/97 Preliminary/ConfidentialSymbios SYM53C885 PCI-SCSI/Fast Ethernet Multifunction Controller Preliminary   Data Manual v3.0http://cesdis.gsfc.nasa.gov/linux/misc/NWay.htmlhttp://cesdis.gsfc.nasa.gov/linux/misc/100mbps.htmlIVc. ErrataSee Packet Engines confidential appendix (prototype chips only).*/enum pci_id_flags_bits {	/* Set PCI command register bits before calling probe1(). */	PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,	/* Read and map the single following PCI BAR. */	PCI_ADDR0=0<<4, PCI_ADDR1=1<<4, PCI_ADDR2=2<<4, PCI_ADDR3=3<<4,	PCI_ADDR_64BITS=0x100, PCI_NO_ACPI_WAKE=0x200, PCI_NO_MIN_LATENCY=0x400,	PCI_UNUSED_IRQ=0x800,};enum capability_flags {	HasMII=1, FullTxStatus=2, IsGigabit=4, HasMulticastBug=8, FullRxStatus=16,	HasMACAddrBug=32, DontUseEeprom=64, /* Only on early revs.  */};/* The PCI I/O space extent. */#define YELLOWFIN_SIZE 0x100#ifdef USE_IO_OPS#define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_IO  | PCI_ADDR0)#else#define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR1)#endifstruct pci_id_info {        const char *name;        struct match_info {                int     pci, pci_mask, subsystem, subsystem_mask;                int revision, revision_mask;                            /* Only 8 bits. */        } id;        enum pci_id_flags_bits pci_flags;        int io_size;                            /* Needed for I/O region check or ioremap(). */        int drv_flags;                          /* Driver use, intended as capability flags. */};static struct pci_id_info pci_id_tbl[] = {	{"Yellowfin G-NIC Gigabit Ethernet", { 0x07021000, 0xffffffff},	 PCI_IOTYPE, YELLOWFIN_SIZE,	 FullTxStatus | IsGigabit | HasMulticastBug | HasMACAddrBug},	{"Symbios SYM83C885", { 0x07011000, 0xffffffff},	 PCI_IOTYPE, YELLOWFIN_SIZE, HasMII | DontUseEeprom },	{0,},};static struct pci_device_id yellowfin_pci_tbl[] __devinitdata = {	{ 0x1000, 0x0702, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },	{ 0x1000, 0x0701, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },	{ 0, }};MODULE_DEVICE_TABLE (pci, yellowfin_pci_tbl);/* Offsets to the Yellowfin registers.  Various sizes and alignments. */enum yellowfin_offsets {	TxCtrl=0x00, TxStatus=0x04, TxPtr=0x0C,	TxIntrSel=0x10, TxBranchSel=0x14, TxWaitSel=0x18,	RxCtrl=0x40, RxStatus=0x44, RxPtr=0x4C,	RxIntrSel=0x50, RxBranchSel=0x54, RxWaitSel=0x58,	EventStatus=0x80, IntrEnb=0x82, IntrClear=0x84, IntrStatus=0x86,	ChipRev=0x8C, DMACtrl=0x90, TxThreshold=0x94,	Cnfg=0xA0, FrameGap0=0xA2, FrameGap1=0xA4,	MII_Cmd=0xA6, MII_Addr=0xA8, MII_Wr_Data=0xAA, MII_Rd_Data=0xAC,	MII_Status=0xAE,	RxDepth=0xB8, FlowCtrl=0xBC,	AddrMode=0xD0, StnAddr=0xD2, HashTbl=0xD8, FIFOcfg=0xF8,	EEStatus=0xF0, EECtrl=0xF1, EEAddr=0xF2, EERead=0xF3, EEWrite=0xF4,	EEFeature=0xF5,};/* The Yellowfin Rx and Tx buffer descriptors.   Elements are written as 32 bit for endian portability. */struct yellowfin_desc {	u32 dbdma_cmd;	u32 addr;	u32 branch_addr;	u32 result_status;};struct tx_status_words {#ifdef __BIG_ENDIAN	u16 tx_errs;	u16 tx_cnt;	u16 paused;	u16 total_tx_cnt;#else  /* Little endian chips. */	u16 tx_cnt;	u16 tx_errs;	u16 total_tx_cnt;	u16 paused;#endif /* __BIG_ENDIAN */};/* Bits in yellowfin_desc.cmd */enum desc_cmd_bits {	CMD_TX_PKT=0x10000000, CMD_RX_BUF=0x20000000, CMD_TXSTATUS=0x30000000,	CMD_NOP=0x60000000, CMD_STOP=0x70000000,	BRANCH_ALWAYS=0x0C0000, INTR_ALWAYS=0x300000, WAIT_ALWAYS=0x030000,	BRANCH_IFTRUE=0x040000,};/* Bits in yellowfin_desc.status */enum desc_status_bits { RX_EOP=0x0040, };/* Bits in the interrupt status/mask registers. */enum intr_status_bits {	IntrRxDone=0x01, IntrRxInvalid=0x02, IntrRxPCIFault=0x04,IntrRxPCIErr=0x08,	IntrTxDone=0x10, IntrTxInvalid=0x20, IntrTxPCIFault=0x40,IntrTxPCIErr=0x80,	IntrEarlyRx=0x100, IntrWakeup=0x200, };#define PRIV_ALIGN	31 	/* Required alignment mask */#define MII_CNT		4struct yellowfin_private {	/* Descriptor rings first for alignment.	   Tx requires a second descriptor for status. */	struct yellowfin_desc *rx_ring;	struct yellowfin_desc *tx_ring;	struct sk_buff* rx_skbuff[RX_RING_SIZE];	struct sk_buff* tx_skbuff[TX_RING_SIZE];	dma_addr_t rx_ring_dma;	dma_addr_t tx_ring_dma;	struct tx_status_words *tx_status;	dma_addr_t tx_status_dma;	struct timer_list timer;	/* Media selection timer. */	struct net_device_stats stats;	/* Frequently used and paired value: keep adjacent for cache effect. */	int chip_id, drv_flags;	struct pci_dev *pci_dev;	unsigned int cur_rx, dirty_rx;		/* Producer/consumer ring indices */	unsigned int rx_buf_sz;				/* Based on MTU+slack. */	struct tx_status_words *tx_tail_desc;	unsigned int cur_tx, dirty_tx;	int tx_threshold;	unsigned int tx_full:1;				/* The Tx queue is full. */	unsigned int full_duplex:1;			/* Full-duplex operation requested. */	unsigned int duplex_lock:1;	unsigned int medialock:1;			/* Do not sense media. */	unsigned int default_port:4;		/* Last dev->if_port value. */

⌨️ 快捷键说明

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