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

📄 forcedeth.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * forcedeth: Ethernet driver for NVIDIA nForce media access controllers. * * Note: This driver is a cleanroom reimplementation based on reverse *      engineered documentation written by Carl-Daniel Hailfinger *      and Andrew de Quincey. * * NVIDIA, nForce and other NVIDIA marks are trademarks or registered * trademarks of NVIDIA Corporation in the United States and other * countries. * * Copyright (C) 2003,4,5 Manfred Spraul * Copyright (C) 2004 Andrew de Quincey (wol support) * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane *		IRQ rate fixes, bigendian fixes, cleanups, verification) * Copyright (c) 2004,5,6 NVIDIA Corporation * * 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; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * Changelog: * 	0.01: 05 Oct 2003: First release that compiles without warnings. * 	0.02: 05 Oct 2003: Fix bug for nv_drain_tx: do not try to free NULL skbs. * 			   Check all PCI BARs for the register window. * 			   udelay added to mii_rw. * 	0.03: 06 Oct 2003: Initialize dev->irq. * 	0.04: 07 Oct 2003: Initialize np->lock, reduce handled irqs, add printks. * 	0.05: 09 Oct 2003: printk removed again, irq status print tx_timeout. * 	0.06: 10 Oct 2003: MAC Address read updated, pff flag generation updated, * 			   irq mask updated * 	0.07: 14 Oct 2003: Further irq mask updates. * 	0.08: 20 Oct 2003: rx_desc.Length initialization added, nv_alloc_rx refill * 			   added into irq handler, NULL check for drain_ring. * 	0.09: 20 Oct 2003: Basic link speed irq implementation. Only handle the * 			   requested interrupt sources. * 	0.10: 20 Oct 2003: First cleanup for release. * 	0.11: 21 Oct 2003: hexdump for tx added, rx buffer sizes increased. * 			   MAC Address init fix, set_multicast cleanup. * 	0.12: 23 Oct 2003: Cleanups for release. * 	0.13: 25 Oct 2003: Limit for concurrent tx packets increased to 10. * 			   Set link speed correctly. start rx before starting * 			   tx (nv_start_rx sets the link speed). * 	0.14: 25 Oct 2003: Nic dependant irq mask. * 	0.15: 08 Nov 2003: fix smp deadlock with set_multicast_list during * 			   open. * 	0.16: 15 Nov 2003: include file cleanup for ppc64, rx buffer size * 			   increased to 1628 bytes. * 	0.17: 16 Nov 2003: undo rx buffer size increase. Substract 1 from * 			   the tx length. * 	0.18: 17 Nov 2003: fix oops due to late initialization of dev_stats * 	0.19: 29 Nov 2003: Handle RxNoBuf, detect & handle invalid mac * 			   addresses, really stop rx if already running * 			   in nv_start_rx, clean up a bit. * 	0.20: 07 Dec 2003: alloc fixes * 	0.21: 12 Jan 2004: additional alloc fix, nic polling fix. *	0.22: 19 Jan 2004: reprogram timer to a sane rate, avoid lockup *			   on close. *	0.23: 26 Jan 2004: various small cleanups *	0.24: 27 Feb 2004: make driver even less anonymous in backtraces *	0.25: 09 Mar 2004: wol support *	0.26: 03 Jun 2004: netdriver specific annotation, sparse-related fixes *	0.27: 19 Jun 2004: Gigabit support, new descriptor rings, *			   added CK804/MCP04 device IDs, code fixes *			   for registers, link status and other minor fixes. *	0.28: 21 Jun 2004: Big cleanup, making driver mostly endian safe *	0.29: 31 Aug 2004: Add backup timer for link change notification. *	0.30: 25 Sep 2004: rx checksum support for nf 250 Gb. Add rx reset *			   into nv_close, otherwise reenabling for wol can *			   cause DMA to kfree'd memory. *	0.31: 14 Nov 2004: ethtool support for getting/setting link *			   capabilities. *	0.32: 16 Apr 2005: RX_ERROR4 handling added. *	0.33: 16 May 2005: Support for MCP51 added. *	0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics. *	0.35: 26 Jun 2005: Support for MCP55 added. *	0.36: 28 Jun 2005: Add jumbo frame support. *	0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list *	0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of *			   per-packet flags. *	0.39: 18 Jul 2005: Add 64bit descriptor support. *	0.40: 19 Jul 2005: Add support for mac address change. *	0.41: 30 Jul 2005: Write back original MAC in nv_close instead *			   of nv_remove *	0.42: 06 Aug 2005: Fix lack of link speed initialization *			   in the second (and later) nv_open call *	0.43: 10 Aug 2005: Add support for tx checksum. *	0.44: 20 Aug 2005: Add support for scatter gather and segmentation. *	0.45: 18 Sep 2005: Remove nv_stop/start_rx from every link check *	0.46: 20 Oct 2005: Add irq optimization modes. *	0.47: 26 Oct 2005: Add phyaddr 0 in phy scan. *	0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single *	0.49: 10 Dec 2005: Fix tso for large buffers. *	0.50: 20 Jan 2006: Add 8021pq tagging support. *	0.51: 20 Jan 2006: Add 64bit consistent memory allocation for rings. *	0.52: 20 Jan 2006: Add MSI/MSIX support. *	0.53: 19 Mar 2006: Fix init from low power mode and add hw reset. *	0.54: 21 Mar 2006: Fix spin locks for multi irqs and cleanup. *	0.55: 22 Mar 2006: Add flow control (pause frame). *	0.56: 22 Mar 2006: Additional ethtool config and moduleparam support. *	0.57: 14 May 2006: Mac address set in probe/remove and order corrections. *	0.58: 30 Oct 2006: Added support for sideband management unit. *	0.59: 30 Oct 2006: Added support for recoverable error. *	0.60: 20 Jan 2007: Code optimizations for rings, rx & tx data paths, and stats. * * Known bugs: * We suspect that on some hardware no TX done interrupts are generated. * This means recovery from netif_stop_queue only happens if the hw timer * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT) * and the timer is active in the IRQMask, or if a rx packet arrives by chance. * If your hardware reliably generates tx done interrupts, then you can remove * DEV_NEED_TIMERIRQ from the driver_data flags. * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few * superfluous timer interrupts from the nic. */#ifdef CONFIG_FORCEDETH_NAPI#define DRIVERNAPI "-NAPI"#else#define DRIVERNAPI#endif#define FORCEDETH_VERSION		"0.61"#define DRV_NAME			"forcedeth"#include <linux/module.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/interrupt.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/delay.h>#include <linux/spinlock.h>#include <linux/ethtool.h>#include <linux/timer.h>#include <linux/skbuff.h>#include <linux/mii.h>#include <linux/random.h>#include <linux/init.h>#include <linux/if_vlan.h>#include <linux/dma-mapping.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/uaccess.h>#include <asm/system.h>#if 0#define dprintk			printk#else#define dprintk(x...)		do { } while (0)#endif#define TX_WORK_PER_LOOP  64#define RX_WORK_PER_LOOP  64/* * Hardware access: */#define DEV_NEED_TIMERIRQ	0x0001  /* set the timer irq flag in the irq mask */#define DEV_NEED_LINKTIMER	0x0002	/* poll link settings. Relies on the timer irq */#define DEV_HAS_LARGEDESC	0x0004	/* device supports jumbo frames and needs packet format 2 */#define DEV_HAS_HIGH_DMA        0x0008  /* device supports 64bit dma */#define DEV_HAS_CHECKSUM        0x0010  /* device supports tx and rx checksum offloads */#define DEV_HAS_VLAN            0x0020  /* device supports vlan tagging and striping */#define DEV_HAS_MSI             0x0040  /* device supports MSI */#define DEV_HAS_MSI_X           0x0080  /* device supports MSI-X */#define DEV_HAS_POWER_CNTRL     0x0100  /* device supports power savings */#define DEV_HAS_PAUSEFRAME_TX   0x0200  /* device supports tx pause frames */#define DEV_HAS_STATISTICS_V1   0x0400  /* device supports hw statistics version 1 */#define DEV_HAS_STATISTICS_V2   0x0800  /* device supports hw statistics version 2 */#define DEV_HAS_TEST_EXTENDED   0x1000  /* device supports extended diagnostic test */#define DEV_HAS_MGMT_UNIT       0x2000  /* device supports management unit */#define DEV_HAS_CORRECT_MACADDR 0x4000  /* device supports correct mac address order */enum {	NvRegIrqStatus = 0x000,#define NVREG_IRQSTAT_MIIEVENT	0x040#define NVREG_IRQSTAT_MASK		0x81ff	NvRegIrqMask = 0x004,#define NVREG_IRQ_RX_ERROR		0x0001#define NVREG_IRQ_RX			0x0002#define NVREG_IRQ_RX_NOBUF		0x0004#define NVREG_IRQ_TX_ERR		0x0008#define NVREG_IRQ_TX_OK			0x0010#define NVREG_IRQ_TIMER			0x0020#define NVREG_IRQ_LINK			0x0040#define NVREG_IRQ_RX_FORCED		0x0080#define NVREG_IRQ_TX_FORCED		0x0100#define NVREG_IRQ_RECOVER_ERROR		0x8000#define NVREG_IRQMASK_THROUGHPUT	0x00df#define NVREG_IRQMASK_CPU		0x0060#define NVREG_IRQ_TX_ALL		(NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)#define NVREG_IRQ_RX_ALL		(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)#define NVREG_IRQ_OTHER			(NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)#define NVREG_IRQ_UNKNOWN	(~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \					NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \					NVREG_IRQ_TX_FORCED|NVREG_IRQ_RECOVER_ERROR))	NvRegUnknownSetupReg6 = 0x008,#define NVREG_UNKSETUP6_VAL		3/* * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms */	NvRegPollingInterval = 0x00c,#define NVREG_POLL_DEFAULT_THROUGHPUT	970 /* backup tx cleanup if loop max reached */#define NVREG_POLL_DEFAULT_CPU	13	NvRegMSIMap0 = 0x020,	NvRegMSIMap1 = 0x024,	NvRegMSIIrqMask = 0x030,#define NVREG_MSI_VECTOR_0_ENABLED 0x01	NvRegMisc1 = 0x080,#define NVREG_MISC1_PAUSE_TX	0x01#define NVREG_MISC1_HD		0x02#define NVREG_MISC1_FORCE	0x3b0f3c	NvRegMacReset = 0x3c,#define NVREG_MAC_RESET_ASSERT	0x0F3	NvRegTransmitterControl = 0x084,#define NVREG_XMITCTL_START	0x01#define NVREG_XMITCTL_MGMT_ST	0x40000000#define NVREG_XMITCTL_SYNC_MASK		0x000f0000#define NVREG_XMITCTL_SYNC_NOT_READY	0x0#define NVREG_XMITCTL_SYNC_PHY_INIT	0x00040000#define NVREG_XMITCTL_MGMT_SEMA_MASK	0x00000f00#define NVREG_XMITCTL_MGMT_SEMA_FREE	0x0#define NVREG_XMITCTL_HOST_SEMA_MASK	0x0000f000#define NVREG_XMITCTL_HOST_SEMA_ACQ	0x0000f000#define NVREG_XMITCTL_HOST_LOADED	0x00004000#define NVREG_XMITCTL_TX_PATH_EN	0x01000000	NvRegTransmitterStatus = 0x088,#define NVREG_XMITSTAT_BUSY	0x01	NvRegPacketFilterFlags = 0x8c,#define NVREG_PFF_PAUSE_RX	0x08#define NVREG_PFF_ALWAYS	0x7F0000#define NVREG_PFF_PROMISC	0x80#define NVREG_PFF_MYADDR	0x20#define NVREG_PFF_LOOPBACK	0x10	NvRegOffloadConfig = 0x90,#define NVREG_OFFLOAD_HOMEPHY	0x601#define NVREG_OFFLOAD_NORMAL	RX_NIC_BUFSIZE	NvRegReceiverControl = 0x094,#define NVREG_RCVCTL_START	0x01#define NVREG_RCVCTL_RX_PATH_EN	0x01000000	NvRegReceiverStatus = 0x98,#define NVREG_RCVSTAT_BUSY	0x01	NvRegRandomSeed = 0x9c,#define NVREG_RNDSEED_MASK	0x00ff#define NVREG_RNDSEED_FORCE	0x7f00#define NVREG_RNDSEED_FORCE2	0x2d00#define NVREG_RNDSEED_FORCE3	0x7400	NvRegTxDeferral = 0xA0,#define NVREG_TX_DEFERRAL_DEFAULT	0x15050f#define NVREG_TX_DEFERRAL_RGMII_10_100	0x16070f#define NVREG_TX_DEFERRAL_RGMII_1000	0x14050f	NvRegRxDeferral = 0xA4,#define NVREG_RX_DEFERRAL_DEFAULT	0x16	NvRegMacAddrA = 0xA8,	NvRegMacAddrB = 0xAC,	NvRegMulticastAddrA = 0xB0,#define NVREG_MCASTADDRA_FORCE	0x01	NvRegMulticastAddrB = 0xB4,	NvRegMulticastMaskA = 0xB8,	NvRegMulticastMaskB = 0xBC,	NvRegPhyInterface = 0xC0,#define PHY_RGMII		0x10000000	NvRegTxRingPhysAddr = 0x100,	NvRegRxRingPhysAddr = 0x104,	NvRegRingSizes = 0x108,#define NVREG_RINGSZ_TXSHIFT 0#define NVREG_RINGSZ_RXSHIFT 16	NvRegTransmitPoll = 0x10c,#define NVREG_TRANSMITPOLL_MAC_ADDR_REV	0x00008000	NvRegLinkSpeed = 0x110,#define NVREG_LINKSPEED_FORCE 0x10000#define NVREG_LINKSPEED_10	1000#define NVREG_LINKSPEED_100	100#define NVREG_LINKSPEED_1000	50#define NVREG_LINKSPEED_MASK	(0xFFF)	NvRegUnknownSetupReg5 = 0x130,#define NVREG_UNKSETUP5_BIT31	(1<<31)	NvRegTxWatermark = 0x13c,#define NVREG_TX_WM_DESC1_DEFAULT	0x0200010#define NVREG_TX_WM_DESC2_3_DEFAULT	0x1e08000#define NVREG_TX_WM_DESC2_3_1000	0xfe08000	NvRegTxRxControl = 0x144,#define NVREG_TXRXCTL_KICK	0x0001#define NVREG_TXRXCTL_BIT1	0x0002#define NVREG_TXRXCTL_BIT2	0x0004#define NVREG_TXRXCTL_IDLE	0x0008#define NVREG_TXRXCTL_RESET	0x0010#define NVREG_TXRXCTL_RXCHECK	0x0400#define NVREG_TXRXCTL_DESC_1	0#define NVREG_TXRXCTL_DESC_2	0x002100#define NVREG_TXRXCTL_DESC_3	0xc02200#define NVREG_TXRXCTL_VLANSTRIP 0x00040#define NVREG_TXRXCTL_VLANINS	0x00080	NvRegTxRingPhysAddrHigh = 0x148,	NvRegRxRingPhysAddrHigh = 0x14C,	NvRegTxPauseFrame = 0x170,#define NVREG_TX_PAUSEFRAME_DISABLE	0x1ff0080#define NVREG_TX_PAUSEFRAME_ENABLE	0x0c00030	NvRegMIIStatus = 0x180,#define NVREG_MIISTAT_ERROR		0x0001#define NVREG_MIISTAT_LINKCHANGE	0x0008#define NVREG_MIISTAT_MASK		0x000f#define NVREG_MIISTAT_MASK2		0x000f	NvRegMIIMask = 0x184,#define NVREG_MII_LINKCHANGE		0x0008	NvRegAdapterControl = 0x188,#define NVREG_ADAPTCTL_START	0x02#define NVREG_ADAPTCTL_LINKUP	0x04#define NVREG_ADAPTCTL_PHYVALID	0x40000#define NVREG_ADAPTCTL_RUNNING	0x100000#define NVREG_ADAPTCTL_PHYSHIFT	24	NvRegMIISpeed = 0x18c,#define NVREG_MIISPEED_BIT8	(1<<8)#define NVREG_MIIDELAY	5	NvRegMIIControl = 0x190,#define NVREG_MIICTL_INUSE	0x08000#define NVREG_MIICTL_WRITE	0x00400#define NVREG_MIICTL_ADDRSHIFT	5	NvRegMIIData = 0x194,	NvRegWakeUpFlags = 0x200,#define NVREG_WAKEUPFLAGS_VAL		0x7770#define NVREG_WAKEUPFLAGS_BUSYSHIFT	24#define NVREG_WAKEUPFLAGS_ENABLESHIFT	16#define NVREG_WAKEUPFLAGS_D3SHIFT	12#define NVREG_WAKEUPFLAGS_D2SHIFT	8#define NVREG_WAKEUPFLAGS_D1SHIFT	4#define NVREG_WAKEUPFLAGS_D0SHIFT	0#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT		0x01#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT	0x02#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE	0x04#define NVREG_WAKEUPFLAGS_ENABLE	0x1111	NvRegPatternCRC = 0x204,	NvRegPatternMask = 0x208,	NvRegPowerCap = 0x268,#define NVREG_POWERCAP_D3SUPP	(1<<30)#define NVREG_POWERCAP_D2SUPP	(1<<26)#define NVREG_POWERCAP_D1SUPP	(1<<25)	NvRegPowerState = 0x26c,#define NVREG_POWERSTATE_POWEREDUP	0x8000#define NVREG_POWERSTATE_VALID		0x0100#define NVREG_POWERSTATE_MASK		0x0003#define NVREG_POWERSTATE_D0		0x0000#define NVREG_POWERSTATE_D1		0x0001#define NVREG_POWERSTATE_D2		0x0002#define NVREG_POWERSTATE_D3		0x0003	NvRegTxCnt = 0x280,	NvRegTxZeroReXmt = 0x284,	NvRegTxOneReXmt = 0x288,	NvRegTxManyReXmt = 0x28c,	NvRegTxLateCol = 0x290,	NvRegTxUnderflow = 0x294,	NvRegTxLossCarrier = 0x298,	NvRegTxExcessDef = 0x29c,	NvRegTxRetryErr = 0x2a0,	NvRegRxFrameErr = 0x2a4,	NvRegRxExtraByte = 0x2a8,	NvRegRxLateCol = 0x2ac,	NvRegRxRunt = 0x2b0,	NvRegRxFrameTooLong = 0x2b4,	NvRegRxOverflow = 0x2b8,	NvRegRxFCSErr = 0x2bc,	NvRegRxFrameAlignErr = 0x2c0,	NvRegRxLenErr = 0x2c4,	NvRegRxUnicast = 0x2c8,	NvRegRxMulticast = 0x2cc,	NvRegRxBroadcast = 0x2d0,	NvRegTxDef = 0x2d4,	NvRegTxFrame = 0x2d8,	NvRegRxCnt = 0x2dc,	NvRegTxPause = 0x2e0,	NvRegRxPause = 0x2e4,	NvRegRxDropFrame = 0x2e8,	NvRegVlanControl = 0x300,#define NVREG_VLANCONTROL_ENABLE	0x2000	NvRegMSIXMap0 = 0x3e0,	NvRegMSIXMap1 = 0x3e4,	NvRegMSIXIrqStatus = 0x3f0,	NvRegPowerState2 = 0x600,#define NVREG_POWERSTATE2_POWERUP_MASK		0x0F11#define NVREG_POWERSTATE2_POWERUP_REV_A3	0x0001};/* Big endian: should work, but is untested */struct ring_desc {	__le32 buf;	__le32 flaglen;};struct ring_desc_ex {	__le32 bufhigh;	__le32 buflow;	__le32 txvlan;	__le32 flaglen;};

⌨️ 快捷键说明

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