📄 eepro.c
字号:
/* eepro.c: Intel EtherExpress Pro/10 device driver for Linux. *//* Written 1994, 1995,1996 by Bao C. Ha. Copyright (C) 1994, 1995,1996 by Bao C. Ha. This software may be used and distributed according to the terms of the GNU Public License, incorporated herein by reference. The author may be reached at bao.ha@srs.gov or 418 Hastings Place, Martinez, GA 30907. Things remaining to do: Better record keeping of errors. Eliminate transmit interrupt to reduce overhead. Implement "concurrent processing". I won't be doing it! Bugs: If you have a problem of not detecting the 82595 during a reboot (warm reset), disable the FLASH memory should fix it. This is a compatibility hardware problem. Versions: 0.12b misc fixes (aris, 06/26/2000) 0.12a port of version 0.12a of 2.2.x kernels to 2.3.x (aris (aris@conectiva.com.br), 05/19/2000) 0.11e some tweaks about multiple cards support (PdP, jul/aug 1999) 0.11d added __initdata, __init stuff; call spin_lock_init in eepro_probe1. Replaced "eepro" by dev->name. Augmented the code protected by spin_lock in interrupt routine (PdP, 12/12/1998) 0.11c minor cleanup (PdP, RMC, 09/12/1998) 0.11b Pascal Dupuis (dupuis@lei.ucl.ac.be): works as a module under 2.1.xx. Debug messages are flagged as KERN_DEBUG to avoid console flooding. Added locking at critical parts. Now the dawn thing is SMP safe. 0.11a Attempt to get 2.1.xx support up (RMC) 0.11 Brian Candler added support for multiple cards. Tested as a module, no idea if it works when compiled into kernel. 0.10e Rick Bressler notified me that ifconfig up;ifconfig down fails because the irq is lost somewhere. Fixed that by moving request_irq and free_irq to eepro_open and eepro_close respectively. 0.10d Ugh! Now Wakeup works. Was seriously broken in my first attempt. I'll need to find a way to specify an ioport other than the default one in the PnP case. PnP definitively sucks. And, yes, this is not the only reason. 0.10c PnP Wakeup Test for 595FX. uncomment #define PnPWakeup; to use. 0.10b Should work now with (some) Pro/10+. At least for me (and my two cards) it does. _No_ guarantee for function with non-Pro/10+ cards! (don't have any) (RMC, 9/11/96) 0.10 Added support for the Etherexpress Pro/10+. The IRQ map was changed significantly from the old pro/10. The new interrupt map was provided by Rainer M. Canavan (Canavan@Zeus.cs.bonn.edu). (BCH, 9/3/96) 0.09 Fixed a race condition in the transmit algorithm, which causes crashes under heavy load with fast pentium computers. The performance should also improve a bit. The size of RX buffer, and hence TX buffer, can also be changed via lilo or insmod. (BCH, 7/31/96) 0.08 Implement 32-bit I/O for the 82595TX and 82595FX based lan cards. Disable full-duplex mode if TPE is not used. (BCH, 4/8/96) 0.07a Fix a stat report which counts every packet as a heart-beat failure. (BCH, 6/3/95) 0.07 Modified to support all other 82595-based lan cards. The IRQ vector of the EtherExpress Pro will be set according to the value saved in the EEPROM. For other cards, I will do autoirq_request() to grab the next available interrupt vector. (BCH, 3/17/95) 0.06a,b Interim released. Minor changes in the comments and print out format. (BCH, 3/9/95 and 3/14/95) 0.06 First stable release that I am comfortable with. (BCH, 3/2/95) 0.05 Complete testing of multicast. (BCH, 2/23/95) 0.04 Adding multicast support. (BCH, 2/14/95) 0.03 First widely alpha release for public testing. (BCH, 2/14/95) */static const char *version = "eepro.c: v0.12b 04/26/2000 aris@conectiva.com.br\n";#include <linux/module.h>/* Sources: This driver wouldn't have been written without the availability of the Crynwr's Lan595 driver source code. It helps me to familiarize with the 82595 chipset while waiting for the Intel documentation. I also learned how to detect the 82595 using the packet driver's technique. This driver is written by cutting and pasting the skeleton.c driver provided by Donald Becker. I also borrowed the EEPROM routine from Donald Becker's 82586 driver. Datasheet for the Intel 82595 (including the TX and FX version). It provides just enough info that the casual reader might think that it documents the i82595. The User Manual for the 82595. It provides a lot of the missing information.*/#include <linux/kernel.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/interrupt.h>#include <linux/ptrace.h>#include <linux/ioport.h>#include <linux/in.h>#include <linux/malloc.h>#include <linux/string.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <linux/errno.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/spinlock.h>#include <linux/init.h>#include <linux/delay.h>#define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )/* I had reports of looong delays with SLOW_DOWN defined as udelay(2) */#define SLOW_DOWN inb(0x80)/* udelay(2) */#define compat_init_data __initdata/* First, a few definitions that the brave might change. *//* A zero-terminated list of I/O addresses to be probed. */static unsigned int eepro_portlist[] compat_init_data = { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};/* note: 0x300 is default, the 595FX supports ALL IO Ports from 0x000 to 0x3F0, some of which are reserved in PCs *//* To try the (not-really PnP Wakeup: *//*#define PnPWakeup*//* use 0 for production, 1 for verification, >2 for debug */#ifndef NET_DEBUG#define NET_DEBUG 0#endifstatic unsigned int net_debug = NET_DEBUG;/* The number of low I/O ports used by the ethercard. */#define EEPRO_IO_EXTENT 16/* Different 82595 chips */#define LAN595 0#define LAN595TX 1#define LAN595FX 2#define LAN595FX_10ISA 3/* Information that need to be kept for each board. */struct eepro_local { struct net_device_stats stats; unsigned rx_start; unsigned tx_start; /* start of the transmit chain */ int tx_last; /* pointer to last packet in the transmit chain */ unsigned tx_end; /* end of the transmit chain (plus 1) */ int eepro; /* 1 for the EtherExpress Pro/10, 2 for the EtherExpress Pro/10+, 0 for other 82595-based lan cards. */ int version; /* a flag to indicate if this is a TX or FX version of the 82595 chip. */ int stepping; spinlock_t lock; /* Serializing lock */ };/* The station (ethernet) address prefix, used for IDing the board. */#define SA_ADDR0 0x00 /* Etherexpress Pro/10 */#define SA_ADDR1 0xaa#define SA_ADDR2 0x00#define GetBit(x,y) ((x & (1<<y))>>y)/* EEPROM Word 0: */#define ee_PnP 0 /* Plug 'n Play enable bit */#define ee_Word1 1 /* Word 1? */#define ee_BusWidth 2 /* 8/16 bit */#define ee_FlashAddr 3 /* Flash Address */#define ee_FlashMask 0x7 /* Mask */#define ee_AutoIO 6 /* */#define ee_reserved0 7 /* =0! */#define ee_Flash 8 /* Flash there? */#define ee_AutoNeg 9 /* Auto Negotiation enabled? */#define ee_IO0 10 /* IO Address LSB */#define ee_IO0Mask 0x /*...*/#define ee_IO1 15 /* IO MSB *//* EEPROM Word 1: */#define ee_IntSel 0 /* Interrupt */#define ee_IntMask 0x7#define ee_LI 3 /* Link Integrity 0= enabled */#define ee_PC 4 /* Polarity Correction 0= enabled */#define ee_TPE_AUI 5 /* PortSelection 1=TPE */#define ee_Jabber 6 /* Jabber prevention 0= enabled */#define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */#define ee_SMOUT 8 /* SMout Pin Control 0= Input */#define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */#define ee_reserved1 10 /* .. 12 =0! */#define ee_AltReady 13 /* Alternate Ready, 0=normal */#define ee_reserved2 14 /* =0! */#define ee_Duplex 15/* Word2,3,4: */#define ee_IA5 0 /*bit start for individual Addr Byte 5 */#define ee_IA4 8 /*bit start for individual Addr Byte 5 */#define ee_IA3 0 /*bit start for individual Addr Byte 5 */#define ee_IA2 8 /*bit start for individual Addr Byte 5 */#define ee_IA1 0 /*bit start for individual Addr Byte 5 */#define ee_IA0 8 /*bit start for individual Addr Byte 5 *//* Word 5: */#define ee_BNC_TPE 0 /* 0=TPE */#define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */#define ee_BootTypeMask 0x3 #define ee_NumConn 3 /* Number of Connections 0= One or Two */#define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */#define ee_PortTPE 5#define ee_PortBNC 6#define ee_PortAUI 7#define ee_PowerMgt 10 /* 0= disabled */#define ee_CP 13 /* Concurrent Processing */#define ee_CPMask 0x7/* Word 6: */#define ee_Stepping 0 /* Stepping info */#define ee_StepMask 0x0F#define ee_BoardID 4 /* Manucaturer Board ID, reserved */#define ee_BoardMask 0x0FFF/* Word 7: */#define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */#define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips *//*..*/#define ee_SIZE 0x40 /* total EEprom Size */#define ee_Checksum 0xBABA /* initial and final value for adding checksum *//* Card identification via EEprom: */#define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */#define ee_addr_id 0x11 /* Word offset for Card ID */#define ee_addr_SN 0x12 /* Serial Number */#define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */#define ee_vendor_intel0 0x25 /* Vendor ID Intel */#define ee_vendor_intel1 0xD4#define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */#define ee_id_eepro10p1 0x31#define TX_TIMEOUT 40/* Index to functions, as function prototypes. */extern int eepro_probe(struct net_device *dev);static int eepro_probe1(struct net_device *dev, short ioaddr);static int eepro_open(struct net_device *dev);static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);static void eepro_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void eepro_rx(struct net_device *dev);static void eepro_transmit_interrupt(struct net_device *dev);static int eepro_close(struct net_device *dev);static struct net_device_stats *eepro_get_stats(struct net_device *dev);static void set_multicast_list(struct net_device *dev);static void eepro_tx_timeout (struct net_device *dev);static int read_eeprom(int ioaddr, int location, struct net_device *dev);static void hardware_send_packet(struct net_device *dev, void *buf, short length);static int eepro_grab_irq(struct net_device *dev);/* Details of the i82595.You will need either the datasheet or the user manual to understand whatis going on here. The 82595 is very different from the 82586, 82593.The receive algorithm in eepro_rx() is just an implementation of theRCV ring structure that the Intel 82595 imposes at the hardware level.The receive buffer is set at 24K, and the transmit buffer is 8K. Iam assuming that the total buffer memory is 32K, which is true for theIntel EtherExpress Pro/10. If it is less than that on a generic card,the driver will be broken.The transmit algorithm in the hardware_send_packet() is similar to theone in the eepro_rx(). The transmit buffer is a ring linked list.I just queue the next available packet to the end of the list. In mysystem, the 82595 is so fast that the list seems to always contain asingle packet. In other systems with faster computers and more congestednetwork traffics, the ring linked list should improve performance byallowing up to 8K worth of packets to be queued.The sizes of the receive and transmit buffers can now be changed via lilo or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"where rx-buffer is in KB unit. Modules uses the parameter mem which isalso in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer." The receive buffer has to be more than 3K or less than 29K. Otherwise,it is reset to the default of 24K, and, hence, 8K for the trasnmitbuffer (transmit-buffer = 32K - receive-buffer).*//* now this section could be used by both boards: the oldies and the ee10: * ee10 uses tx buffer before of rx buffer and the oldies the inverse. * (aris) */#define RAM_SIZE 0x8000#define RCV_HEADER 8#define RCV_DEFAULT_RAM 0x6000#define RCV_RAM rcv_ramstatic unsigned rcv_ram = RCV_DEFAULT_RAM;#define XMT_HEADER 8#define XMT_RAM (RAM_SIZE - RCV_RAM)#define XMT_START ((rcv_start + RCV_RAM) % RAM_SIZE)#define RCV_LOWER_LIMIT (rcv_start >> 8)#define RCV_UPPER_LIMIT (((rcv_start + RCV_RAM) - 2) >> 8)#define XMT_LOWER_LIMIT (XMT_START >> 8)#define XMT_UPPER_LIMIT (((XMT_START + XMT_RAM) - 2) >> 8)#define RCV_START_PRO 0x00#define RCV_START_10 XMT_RAM /* by default the old driver */static unsigned rcv_start = RCV_START_PRO;#define RCV_DONE 0x0008#define RX_OK 0x2000#define RX_ERROR 0x0d81#define TX_DONE_BIT 0x0080#define CHAIN_BIT 0x8000#define XMT_STATUS 0x02#define XMT_CHAIN 0x04#define XMT_COUNT 0x06#define BANK0_SELECT 0x00 #define BANK1_SELECT 0x40 #define BANK2_SELECT 0x80 /* Bank 0 registers */#define COMMAND_REG 0x00 /* Register 0 */#define MC_SETUP 0x03#define XMT_CMD 0x04#define DIAGNOSE_CMD 0x07#define RCV_ENABLE_CMD 0x08#define RCV_DISABLE_CMD 0x0a#define STOP_RCV_CMD 0x0b#define RESET_CMD 0x0e#define POWER_DOWN_CMD 0x18#define RESUME_XMT_CMD 0x1c#define SEL_RESET_CMD 0x1e#define STATUS_REG 0x01 /* Register 1 */#define RX_INT 0x02#define TX_INT 0x04#define EXEC_STATUS 0x30#define ID_REG 0x02 /* Register 2 */#define R_ROBIN_BITS 0xc0 /* round robin counter */#define ID_REG_MASK 0x2c#define ID_REG_SIG 0x24#define AUTO_ENABLE 0x10#define INT_MASK_REG 0x03 /* Register 3 */#define RX_STOP_MASK 0x01#define RX_MASK 0x02#define TX_MASK 0x04#define EXEC_MASK 0x08#define ALL_MASK 0x0f#define IO_32_BIT 0x10#define RCV_BAR 0x04 /* The following are word (16-bit) registers */#define RCV_STOP 0x06#define XMT_BAR_PRO 0x0a#define XMT_BAR_10 0x0bstatic unsigned xmt_bar = XMT_BAR_PRO;#define HOST_ADDRESS_REG 0x0c#define IO_PORT 0x0e#define IO_PORT_32_BIT 0x0c/* Bank 1 registers */#define REG1 0x01#define WORD_WIDTH 0x02#define INT_ENABLE 0x80#define INT_NO_REG 0x02#define RCV_LOWER_LIMIT_REG 0x08#define RCV_UPPER_LIMIT_REG 0x09#define XMT_LOWER_LIMIT_REG_PRO 0x0a#define XMT_UPPER_LIMIT_REG_PRO 0x0b#define XMT_LOWER_LIMIT_REG_10 0x0b#define XMT_UPPER_LIMIT_REG_10 0x0astatic unsigned xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;static unsigned xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;/* Bank 2 registers */#define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */#define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */#define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */#define REG2 0x02#define PRMSC_Mode 0x01#define Multi_IA 0x20#define REG3 0x03#define TPE_BIT 0x04#define BNC_BIT 0x20#define REG13 0x0d#define FDX 0x00#define A_N_ENABLE 0x02 #define I_ADD_REG0 0x04#define I_ADD_REG1 0x05#define I_ADD_REG2 0x06#define I_ADD_REG3 0x07#define I_ADD_REG4 0x08#define I_ADD_REG5 0x09#define EEPROM_REG_PRO 0x0a#define EEPROM_REG_10 0x0b
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -