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

📄 fealnx.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 4 页
字号:
/*	Written 1998-2000 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.	The author may be reached as becker@scyld.com, or C/O	Scyld Computing Corporation	410 Severn Ave., Suite 210	Annapolis MD 21403	Support information and updates available at	http://www.scyld.com/network/pci-skeleton.html	Linux kernel updates:	Version 2.51, Nov 17, 2001 (jgarzik):	- Add ethtool support	- Replace some MII-related magic numbers with constants*/#define DRV_NAME	"fealnx"#define DRV_VERSION	"2.51"#define DRV_RELDATE	"Nov-17-2001"static int debug;		/* 1-> print debug message */static int max_interrupt_work = 20;/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). */static int multicast_filter_limit = 32;/* Set the copy breakpoint for the copy-only-tiny-frames scheme. *//* Setting to > 1518 effectively disables this feature.          */static int rx_copybreak;/* Used to pass the media type, etc.                            *//* Both 'options[]' and 'full_duplex[]' should exist for driver *//* interoperability.                                            *//* The media type is usually passed in 'options[]'.             */#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 };/* Operational parameters that are set at compile time.                 *//* Keep the ring sizes a power of two for compile efficiency.           *//* The compiler will convert <unsigned>'%'<2^N> into a bit mask.        *//* Making the Tx ring too large decreases the effectiveness of channel  *//* bonding and packet priority.                                         *//* There are no ill effects from too-large receive rings.               */// 88-12-9 modify,// #define TX_RING_SIZE    16// #define RX_RING_SIZE    32#define TX_RING_SIZE    6#define RX_RING_SIZE    12#define TX_TOTAL_SIZE	TX_RING_SIZE*sizeof(struct fealnx_desc)#define RX_TOTAL_SIZE	RX_RING_SIZE*sizeof(struct fealnx_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. *//* Include files, designed to support most kernel versions 2.0.0 and later. */#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.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/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/init.h>#include <linux/mii.h>#include <linux/ethtool.h>#include <asm/processor.h>	/* Processor type for cache alignment. */#include <asm/bitops.h>#include <asm/io.h>#include <asm/uaccess.h>/* These identify the driver base version and may not be removed. */static char version[] __devinitdata =KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "\n";/* This driver was written to use PCI memory space, however some x86 systems   work only with I/O space accesses. */#ifndef __alpha__#define USE_IO_OPS#endif#ifdef USE_IO_OPS#undef readb#undef readw#undef readl#undef writeb#undef writew#undef writel#define readb inb#define readw inw#define readl inl#define writeb outb#define writew outw#define writel outl#endif/* Kernel compatibility defines, some common to David Hinds' PCMCIA package. *//* This is only in the support-all-kernels source code. */#define RUN_AT(x) (jiffies + (x))MODULE_AUTHOR("Myson or whoever");MODULE_DESCRIPTION("Myson MTD-8xx 100/10M Ethernet PCI Adapter Driver");MODULE_LICENSE("GPL");MODULE_PARM(max_interrupt_work, "i");//MODULE_PARM(min_pci_latency, "i");MODULE_PARM(debug, "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(multicast_filter_limit, "i");MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM_DESC(max_interrupt_work, "fealnx maximum events handled per interrupt");MODULE_PARM_DESC(debug, "fealnx enable debugging (0-1)");MODULE_PARM_DESC(rx_copybreak, "fealnx copy breakpoint for copy-only-tiny-frames");MODULE_PARM_DESC(multicast_filter_limit, "fealnx maximum number of filtered multicast addresses");MODULE_PARM_DESC(options, "fealnx: Bits 0-3: media type, bit 17: full duplex");MODULE_PARM_DESC(full_duplex, "fealnx full duplex setting(s) (1)");#define MIN_REGION_SIZE 136enum pci_flags_bit {	PCI_USES_IO = 1,	PCI_USES_MEM = 2,	PCI_USES_MASTER = 4,	PCI_ADDR0 = 0x10 << 0,	PCI_ADDR1 = 0x10 << 1,	PCI_ADDR2 = 0x10 << 2,	PCI_ADDR3 = 0x10 << 3,};/* A chip capabilities table, matching the entries in pci_tbl[] above. */enum chip_capability_flags {	HAS_MII_XCVR,	HAS_CHIP_XCVR,};/* 89/6/13 add, *//* for different PHY */enum phy_type_flags {	MysonPHY = 1,	AhdocPHY = 2,	SeeqPHY = 3,	MarvellPHY = 4,	Myson981 = 5,	LevelOnePHY = 6,	OtherPHY = 10,};struct chip_info {	char *chip_name;	int io_size;	int flags;};static struct chip_info skel_netdrv_tbl[] = {	{"100/10M Ethernet PCI Adapter", 136, HAS_MII_XCVR},	{"100/10M Ethernet PCI Adapter", 136, HAS_CHIP_XCVR},	{"1000/100/10M Ethernet PCI Adapter", 136, HAS_MII_XCVR},};/* Offsets to the Command and Status Registers. */enum fealnx_offsets {	PAR0 = 0x0,		/* physical address 0-3 */	PAR1 = 0x04,		/* physical address 4-5 */	MAR0 = 0x08,		/* multicast address 0-3 */	MAR1 = 0x0C,		/* multicast address 4-7 */	FAR0 = 0x10,		/* flow-control address 0-3 */	FAR1 = 0x14,		/* flow-control address 4-5 */	TCRRCR = 0x18,		/* receive & transmit configuration */	BCR = 0x1C,		/* bus command */	TXPDR = 0x20,		/* transmit polling demand */	RXPDR = 0x24,		/* receive polling demand */	RXCWP = 0x28,		/* receive current word pointer */	TXLBA = 0x2C,		/* transmit list base address */	RXLBA = 0x30,		/* receive list base address */	ISR = 0x34,		/* interrupt status */	IMR = 0x38,		/* interrupt mask */	FTH = 0x3C,		/* flow control high/low threshold */	MANAGEMENT = 0x40,	/* bootrom/eeprom and mii management */	TALLY = 0x44,		/* tally counters for crc and mpa */	TSR = 0x48,		/* tally counter for transmit status */	BMCRSR = 0x4c,		/* basic mode control and status */	PHYIDENTIFIER = 0x50,	/* phy identifier */	ANARANLPAR = 0x54,	/* auto-negotiation advertisement and link				   partner ability */	ANEROCR = 0x58,		/* auto-negotiation expansion and pci conf. */	BPREMRPSR = 0x5c,	/* bypass & receive error mask and phy status */};/* Bits in the interrupt status/enable registers. *//* The bits in the Intr Status/Enable registers, mostly interrupt sources. */enum intr_status_bits {	RFCON = 0x00020000,	/* receive flow control xon packet */	RFCOFF = 0x00010000,	/* receive flow control xoff packet */	LSCStatus = 0x00008000,	/* link status change */	ANCStatus = 0x00004000,	/* autonegotiation completed */	FBE = 0x00002000,	/* fatal bus error */	FBEMask = 0x00001800,	/* mask bit12-11 */	ParityErr = 0x00000000,	/* parity error */	TargetErr = 0x00001000,	/* target abort */	MasterErr = 0x00000800,	/* master error */	TUNF = 0x00000400,	/* transmit underflow */	ROVF = 0x00000200,	/* receive overflow */	ETI = 0x00000100,	/* transmit early int */	ERI = 0x00000080,	/* receive early int */	CNTOVF = 0x00000040,	/* counter overflow */	RBU = 0x00000020,	/* receive buffer unavailable */	TBU = 0x00000010,	/* transmit buffer unavilable */	TI = 0x00000008,	/* transmit interrupt */	RI = 0x00000004,	/* receive interrupt */	RxErr = 0x00000002,	/* receive error */};/* Bits in the NetworkConfig register. */enum rx_mode_bits {	RxModeMask = 0xe0,	PROM = 0x80,		/* promiscuous mode */	AB = 0x40,		/* accept broadcast */	AM = 0x20,		/* accept mutlicast */	ARP = 0x08,		/* receive runt pkt */	ALP = 0x04,		/* receive long pkt */	SEP = 0x02,		/* receive error pkt */};/* The Tulip Rx and Tx buffer descriptors. */struct fealnx_desc {	s32 status;	s32 control;	u32 buffer;	u32 next_desc;	struct fealnx_desc *next_desc_logical;	struct sk_buff *skbuff;	u32 reserved1;	u32 reserved2;};/* Bits in network_desc.status */enum rx_desc_status_bits {	RXOWN = 0x80000000,	/* own bit */	FLNGMASK = 0x0fff0000,	/* frame length */	FLNGShift = 16,	MARSTATUS = 0x00004000,	/* multicast address received */	BARSTATUS = 0x00002000,	/* broadcast address received */	PHYSTATUS = 0x00001000,	/* physical address received */	RXFSD = 0x00000800,	/* first descriptor */	RXLSD = 0x00000400,	/* last descriptor */	ErrorSummary = 0x80,	/* error summary */	RUNT = 0x40,		/* runt packet received */	LONG = 0x20,		/* long packet received */	FAE = 0x10,		/* frame align error */	CRC = 0x08,		/* crc error */	RXER = 0x04,		/* receive error */};enum rx_desc_control_bits {	RXIC = 0x00800000,	/* interrupt control */	RBSShift = 0,};enum tx_desc_status_bits {	TXOWN = 0x80000000,	/* own bit */	JABTO = 0x00004000,	/* jabber timeout */	CSL = 0x00002000,	/* carrier sense lost */	LC = 0x00001000,	/* late collision */	EC = 0x00000800,	/* excessive collision */	UDF = 0x00000400,	/* fifo underflow */	DFR = 0x00000200,	/* deferred */	HF = 0x00000100,	/* heartbeat fail */	NCRMask = 0x000000ff,	/* collision retry count */	NCRShift = 0,};enum tx_desc_control_bits {	TXIC = 0x80000000,	/* interrupt control */	ETIControl = 0x40000000,	/* early transmit interrupt */	TXLD = 0x20000000,	/* last descriptor */	TXFD = 0x10000000,	/* first descriptor */	CRCEnable = 0x08000000,	/* crc control */	PADEnable = 0x04000000,	/* padding control */	RetryTxLC = 0x02000000,	/* retry late collision */	PKTSMask = 0x3ff800,	/* packet size bit21-11 */	PKTSShift = 11,	TBSMask = 0x000007ff,	/* transmit buffer bit 10-0 */	TBSShift = 0,};/* BootROM/EEPROM/MII Management Register */#define MASK_MIIR_MII_READ       0x00000000#define MASK_MIIR_MII_WRITE      0x00000008#define MASK_MIIR_MII_MDO        0x00000004#define MASK_MIIR_MII_MDI        0x00000002#define MASK_MIIR_MII_MDC        0x00000001/* ST+OP+PHYAD+REGAD+TA */#define OP_READ             0x6000	/* ST:01+OP:10+PHYAD+REGAD+TA:Z0 */#define OP_WRITE            0x5002	/* ST:01+OP:01+PHYAD+REGAD+TA:10 *//* ------------------------------------------------------------------------- *//*      Constants for Myson PHY                                              *//* ------------------------------------------------------------------------- */#define MysonPHYID      0xd0000302/* 89-7-27 add, (begin) */#define MysonPHYID0     0x0302#define StatusRegister  18#define SPEED100        0x0400	// bit10#define FULLMODE        0x0800	// bit11/* 89-7-27 add, (end) *//* ------------------------------------------------------------------------- *//*      Constants for Seeq 80225 PHY                                         *//* ------------------------------------------------------------------------- */#define SeeqPHYID0      0x0016#define MIIRegister18   18#define SPD_DET_100     0x80#define DPLX_DET_FULL   0x40/* ------------------------------------------------------------------------- *//*      Constants for Ahdoc 101 PHY                                          *//* ------------------------------------------------------------------------- */#define AhdocPHYID0     0x0022#define DiagnosticReg   18#define DPLX_FULL       0x0800#define Speed_100       0x0400/* 89/6/13 add, *//* -------------------------------------------------------------------------- *//*      Constants                                                             *//* -------------------------------------------------------------------------- */#define MarvellPHYID0           0x0141#define LevelOnePHYID0		0x0013#define MII1000BaseTControlReg  9#define MII1000BaseTStatusReg   10#define SpecificReg		17/* for 1000BaseT Control Register */#define PHYAbletoPerform1000FullDuplex  0x0200#define PHYAbletoPerform1000HalfDuplex  0x0100#define PHY1000AbilityMask              0x300// for phy specific status register, marvell phy.#define SpeedMask       0x0c000#define Speed_1000M     0x08000#define Speed_100M      0x4000#define Speed_10M       0#define Full_Duplex     0x2000// 89/12/29 add, for phy specific status register, levelone phy, (begin)#define LXT1000_100M    0x08000#define LXT1000_1000M   0x0c000#define LXT1000_Full    0x200// 89/12/29 add, for phy specific status register, levelone phy, (end)/* for 3-in-1 case */#define PS10            0x00080000#define FD              0x00100000#define PS1000          0x00010000#define LinkIsUp2	0x00040000/* for PHY */#define LinkIsUp        0x0004struct netdev_private {	/* Descriptor rings first for alignment. */	struct fealnx_desc *rx_ring;	struct fealnx_desc *tx_ring;	dma_addr_t rx_ring_dma;	dma_addr_t tx_ring_dma;	spinlock_t lock;	struct net_device_stats stats;	/* Media monitoring timer. */	struct timer_list timer;	/* Frequently used values: keep some adjacent for cache effect. */	int flags;	struct pci_dev *pci_dev;	unsigned long crvalue;	unsigned long bcrvalue;	unsigned long imrvalue;	struct fealnx_desc *cur_rx;	struct fealnx_desc *lack_rxbuf;	int really_rx_count;	struct fealnx_desc *cur_tx;	struct fealnx_desc *cur_tx_copy;	int really_tx_count;	int free_tx_count;	unsigned int rx_buf_sz;	/* Based on MTU+slack. */	/* These values are keep track of the transceiver/media in use. */	unsigned int linkok;	unsigned int line_speed;	unsigned int duplexmode;	unsigned int default_port:4;	/* Last dev->if_port value. */	unsigned int PHYType;	/* MII transceiver section. */	int mii_cnt;		/* MII device addresses. */	unsigned char phys[2];	/* MII device addresses. */	struct mii_if_info mii;};static int mdio_read(struct net_device *dev, int phy_id, int location);static void mdio_write(struct net_device *dev, int phy_id, int location, int value);static int netdev_open(struct net_device *dev);static void getlinktype(struct net_device *dev);static void getlinkstatus(struct net_device *dev);static void netdev_timer(unsigned long data);static void tx_timeout(struct net_device *dev);static void init_ring(struct net_device *dev);static int start_tx(struct sk_buff *skb, struct net_device *dev);static void intr_handler(int irq, void *dev_instance, struct pt_regs *regs);static int netdev_rx(struct net_device *dev);static inline unsigned ether_crc(int length, unsigned char *data);static void set_rx_mode(struct net_device *dev);static struct net_device_stats *get_stats(struct net_device *dev);static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static int netdev_close(struct net_device *dev);static void reset_rx_descriptors(struct net_device *dev);void stop_nic_tx(long ioaddr, long crvalue){	writel(crvalue & (~0x40000), ioaddr + TCRRCR);	/* wait for tx stop */	{		int i = 0, delay = 0x1000;		while ((!(readl(ioaddr + TCRRCR) & 0x04000000)) && (i < delay)) {			++i;		}	}}void stop_nic_rx(long ioaddr, long crvalue){	writel(crvalue & (~0x1), ioaddr + TCRRCR);	/* wait for rx stop */	{		int i = 0, delay = 0x1000;		while ((!(readl(ioaddr + TCRRCR) & 0x00008000)) && (i < delay)) {			++i;		}	}}static int __devinit fealnx_init_one(struct pci_dev *pdev,				     const struct pci_device_id *ent){	struct netdev_private *np;	int i, option, err, irq;	static int card_idx = -1;	char boardname[12];	long ioaddr;	unsigned int chip_id = ent->driver_data;	struct net_device *dev;	void *ring_space;	dma_addr_t ring_dma;	/* when built into the kernel, we only print version if device is found */#ifndef MODULE

⌨️ 快捷键说明

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