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

📄 ethernet.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* $Id: ethernet.c,v 1.22 2004/05/14 07:58:03 starvik Exp $ * * e100net.c: A network driver for the ETRAX 100LX network controller. * * Copyright (c) 1998-2002 Axis Communications AB. * * The outline of this driver comes from skeleton.c. * * $Log: ethernet.c,v $ * Revision 1.22  2004/05/14 07:58:03  starvik * Merge of changes from 2.4 * * Revision 1.20  2004/03/11 11:38:40  starvik * Merge of Linux 2.6.4 * * Revision 1.18  2003/12/03 13:45:46  starvik * Use hardware pad for short packets to prevent information leakage. * * Revision 1.17  2003/07/04 08:27:37  starvik * Merge of Linux 2.5.74 * * Revision 1.16  2003/04/24 08:28:22  starvik * New LED behaviour: LED off when no link * * Revision 1.15  2003/04/09 05:20:47  starvik * Merge of Linux 2.5.67 * * Revision 1.13  2003/03/06 16:11:01  henriken * Off by one error in group address register setting. * * Revision 1.12  2003/02/27 17:24:19  starvik * Corrected Rev to Revision * * Revision 1.11  2003/01/24 09:53:21  starvik * Oops. Initialize GA to 0, not to 1 * * Revision 1.10  2003/01/24 09:50:55  starvik * Initialize GA_0 and GA_1 to 0 to avoid matching of unwanted packets * * Revision 1.9  2002/12/13 07:40:58  starvik * Added basic ethtool interface * Handled out of memory when allocating new buffers * * Revision 1.8  2002/12/11 13:13:57  starvik * Added arch/ to v10 specific includes * Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer) * * Revision 1.7  2002/11/26 09:41:42  starvik * Added e100_set_config (standard interface to set media type) * Added protection against preemptive scheduling * Added standard MII ioctls * * Revision 1.6  2002/11/21 07:18:18  starvik * Timers must be initialized in 2.5.48 * * Revision 1.5  2002/11/20 11:56:11  starvik * Merge of Linux 2.5.48 * * Revision 1.4  2002/11/18 07:26:46  starvik * Linux 2.5 port of latest Linux 2.4 ethernet driver * * Revision 1.33  2002/10/02 20:16:17  hp * SETF, SETS: Use underscored IO_x_ macros rather than incorrect token concatenation * * Revision 1.32  2002/09/16 06:05:58  starvik * Align memory returned by dev_alloc_skb * Moved handling of sent packets to interrupt to avoid reference counting problem * * Revision 1.31  2002/09/10 13:28:23  larsv * Return -EINVAL for unknown ioctls to avoid confusing tools that tests * for supported functionality by issuing special ioctls, i.e. wireless * extensions. * * Revision 1.30  2002/05/07 18:50:08  johana * Correct spelling in comments. * * Revision 1.29  2002/05/06 05:38:49  starvik * Performance improvements: *    Large packets are not copied (breakpoint set to 256 bytes) *    The cache bug workaround is delayed until half of the receive list *      has been used *    Added transmit list *    Transmit interrupts are only enabled when transmit queue is full * * Revision 1.28.2.1  2002/04/30 08:15:51  starvik * Performance improvements: *   Large packets are not copied (breakpoint set to 256 bytes) *   The cache bug workaround is delayed until half of the receive list *     has been used. *   Added transmit list *   Transmit interrupts are only enabled when transmit queue is full * * Revision 1.28  2002/04/22 11:47:21  johana * Fix according to 2.4.19-pre7. time_after/time_before and * missing end of comment. * The patch has a typo for ethernet.c in e100_clear_network_leds(), *  that is fixed here. * * Revision 1.27  2002/04/12 11:55:11  bjornw * Added TODO * * Revision 1.26  2002/03/15 17:11:02  bjornw * Use prepare_rx_descriptor after the CPU has touched the receiving descs * * Revision 1.25  2002/03/08 13:07:53  bjornw * Unnecessary spinlock removed * * Revision 1.24  2002/02/20 12:57:43  fredriks * Replaced MIN() with min(). * * Revision 1.23  2002/02/20 10:58:14  fredriks * Strip the Ethernet checksum (4 bytes) before forwarding a frame to upper layers. * * Revision 1.22  2002/01/30 07:48:22  matsfg * Initiate R_NETWORK_TR_CTRL * * Revision 1.21  2001/11/23 11:54:49  starvik * Added IFF_PROMISC and IFF_ALLMULTI handling in set_multicast_list * Removed compiler warnings * * Revision 1.20  2001/11/12 19:26:00  pkj * * Corrected e100_negotiate() to not assign half to current_duplex when *   it was supposed to compare them... * * Cleaned up failure handling in e100_open(). * * Fixed compiler warnings. * * Revision 1.19  2001/11/09 07:43:09  starvik * Added full duplex support * Added ioctl to set speed and duplex * Clear LED timer only runs when LED is lit * * Revision 1.18  2001/10/03 14:40:43  jonashg * Update rx_bytes counter. * * Revision 1.17  2001/06/11 12:43:46  olof * Modified defines for network LED behavior * * Revision 1.16  2001/05/30 06:12:46  markusl * TxDesc.next should not be set to NULL * * Revision 1.15  2001/05/29 10:27:04  markusl * Updated after review remarks: * +Use IO_EXTRACT * +Handle underrun * * Revision 1.14  2001/05/29 09:20:14  jonashg * Use driver name on printk output so one can tell which driver that complains. * * Revision 1.13  2001/05/09 12:35:59  johana * Use DMA_NBR and IRQ_NBR defines from dma.h and irq.h * * Revision 1.12  2001/04/05 11:43:11  tobiasa * Check dev before panic. * * Revision 1.11  2001/04/04 11:21:05  markusl * Updated according to review remarks * * Revision 1.10  2001/03/26 16:03:06  bjornw * Needs linux/config.h * * Revision 1.9  2001/03/19 14:47:48  pkj * * Make sure there is always a pause after the network LEDs are *   changed so they will not look constantly lit during heavy traffic. * * Always use HZ when setting times relative to jiffies. * * Use LED_NETWORK_SET() when setting the network LEDs. * * Revision 1.8  2001/02/27 13:52:48  bjornw * malloc.h -> slab.h * * Revision 1.7  2001/02/23 13:46:38  bjornw * Spellling check * * Revision 1.6  2001/01/26 15:21:04  starvik * Don't disable interrupts while reading MDIO registers (MDIO is slow) * Corrected promiscuous mode * Improved deallocation of IRQs ("ifconfig eth0 down" now works) * * Revision 1.5  2000/11/29 17:22:22  bjornw * Get rid of the udword types legacy stuff * * Revision 1.4  2000/11/22 16:36:09  bjornw * Please marketing by using the correct case when spelling Etrax. * * Revision 1.3  2000/11/21 16:43:04  bjornw * Minor short->int change * * Revision 1.2  2000/11/08 14:27:57  bjornw * 2.4 port * * Revision 1.1  2000/11/06 13:56:00  bjornw * Verbatim copy of the 1.24 version of e100net.c from elinux * * Revision 1.24  2000/10/04 15:55:23  bjornw * * Use virt_to_phys etc. for DMA addresses * * Removed bogus CHECKSUM_UNNECESSARY * * */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/delay.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/slab.h>#include <linux/string.h>#include <linux/spinlock.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/if.h>#include <linux/mii.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/ethtool.h>#include <asm/arch/svinto.h>/* DMA and register descriptions */#include <asm/io.h>         /* LED_* I/O functions */#include <asm/irq.h>#include <asm/dma.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/ethernet.h>#include <asm/cache.h>//#define ETHDEBUG#define D(x)/* * The name of the card. Is used for messages and in the requests for * io regions, irqs and dma channels */static const char* cardname = "ETRAX 100LX built-in ethernet controller";/* A default ethernet address. Highlevel SW will set the real one later */static struct sockaddr default_mac = {	0,	{ 0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00 }};/* Information that need to be kept for each board. */struct net_local {	struct net_device_stats stats;	/* Tx control lock.  This protects the transmit buffer ring	 * state along with the "tx full" state of the driver.  This	 * means all netif_queue flow control actions are protected	 * by this lock as well.	 */	spinlock_t lock;};typedef struct etrax_eth_descr{	etrax_dma_descr descr;	struct sk_buff* skb;} etrax_eth_descr;/* Some transceivers requires special handling */struct transceiver_ops{	unsigned int oui;	void (*check_speed)(void);	void (*check_duplex)(void);};struct transceiver_ops* transceiver;/* Duplex settings */enum duplex{	half,	full,	autoneg};/* Dma descriptors etc. */#define MAX_MEDIA_DATA_SIZE 1518#define MIN_PACKET_LEN      46#define ETHER_HEAD_LEN      14/* ** MDIO constants.*/#define MDIO_BASE_STATUS_REG                0x1#define MDIO_BASE_CONTROL_REG               0x0#define MDIO_PHY_ID_HIGH_REG                0x2#define MDIO_PHY_ID_LOW_REG                 0x3#define MDIO_BC_NEGOTIATE                0x0200#define MDIO_BC_FULL_DUPLEX_MASK         0x0100#define MDIO_BC_AUTO_NEG_MASK            0x1000#define MDIO_BC_SPEED_SELECT_MASK        0x2000#define MDIO_STATUS_100_FD               0x4000#define MDIO_STATUS_100_HD               0x2000#define MDIO_STATUS_10_FD                0x1000#define MDIO_STATUS_10_HD                0x0800#define MDIO_STATUS_SPEED_DUPLEX_MASK	 0x7800#define MDIO_ADVERTISMENT_REG               0x4#define MDIO_ADVERT_100_FD                0x100#define MDIO_ADVERT_100_HD                0x080#define MDIO_ADVERT_10_FD                 0x040#define MDIO_ADVERT_10_HD                 0x020#define MDIO_LINK_UP_MASK                   0x4#define MDIO_START                          0x1#define MDIO_READ                           0x2#define MDIO_WRITE                          0x1#define MDIO_PREAMBLE              0xfffffffful/* Broadcom specific */#define MDIO_AUX_CTRL_STATUS_REG           0x18#define MDIO_BC_FULL_DUPLEX_IND             0x1#define MDIO_BC_SPEED                       0x2/* TDK specific */#define MDIO_TDK_DIAGNOSTIC_REG              18#define MDIO_TDK_DIAGNOSTIC_RATE          0x400#define MDIO_TDK_DIAGNOSTIC_DPLX          0x800/* Network flash constants */#define NET_FLASH_TIME                  (HZ/50) /* 20 ms */#define NET_FLASH_PAUSE                (HZ/100) /* 10 ms */#define NET_LINK_UP_CHECK_INTERVAL       (2*HZ) /* 2 s   */#define NET_DUPLEX_CHECK_INTERVAL        (2*HZ) /* 2 s   */#define NO_NETWORK_ACTIVITY 0#define NETWORK_ACTIVITY    1#define NBR_OF_RX_DESC     64#define NBR_OF_TX_DESC     256/* Large packets are sent directly to upper layers while small packets are *//* copied (to reduce memory waste). The following constant decides the breakpoint */#define RX_COPYBREAK 256/* Due to a chip bug we need to flush the cache when descriptors are returned *//* to the DMA. To decrease performance impact we return descriptors in chunks. *//* The following constant determines the number of descriptors to return. */#define RX_QUEUE_THRESHOLD  NBR_OF_RX_DESC/2#define GET_BIT(bit,val)   (((val) >> (bit)) & 0x01)/* Define some macros to access ETRAX 100 registers */#define SETF(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \					  IO_FIELD_(reg##_, field##_, val)#define SETS(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \					  IO_STATE_(reg##_, field##_, _##val)static etrax_eth_descr *myNextRxDesc;  /* Points to the next descriptor to                                          to be processed */static etrax_eth_descr *myLastRxDesc;  /* The last processed descriptor */static etrax_eth_descr *myPrevRxDesc;  /* The descriptor right before myNextRxDesc */static etrax_eth_descr RxDescList[NBR_OF_RX_DESC] __attribute__ ((aligned(32)));static etrax_eth_descr* myFirstTxDesc; /* First packet not yet sent */static etrax_eth_descr* myLastTxDesc;  /* End of send queue */static etrax_eth_descr* myNextTxDesc;  /* Next descriptor to use */static etrax_eth_descr TxDescList[NBR_OF_TX_DESC] __attribute__ ((aligned(32)));static unsigned int network_rec_config_shadow = 0;static unsigned int mdio_phy_addr; /* Transciever address */static unsigned int network_tr_ctrl_shadow = 0;/* Network speed indication. */static struct timer_list speed_timer = TIMER_INITIALIZER(NULL, 0, 0);static struct timer_list clear_led_timer = TIMER_INITIALIZER(NULL, 0, 0);static int current_speed; /* Speed read from transceiver */static int current_speed_selection; /* Speed selected by user */static unsigned long led_next_time;static int led_active;static int rx_queue_len;/* Duplex */static struct timer_list duplex_timer = TIMER_INITIALIZER(NULL, 0, 0);static int full_duplex;static enum duplex current_duplex;/* Index to functions, as function prototypes. */static int etrax_ethernet_init(void);static int e100_open(struct net_device *dev);static int e100_set_mac_address(struct net_device *dev, void *addr);static int e100_send_packet(struct sk_buff *skb, struct net_device *dev);static irqreturn_t e100rxtx_interrupt(int irq, void *dev_id, struct pt_regs *regs);static irqreturn_t e100nw_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void e100_rx(struct net_device *dev);static int e100_close(struct net_device *dev);static int e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);static int e100_ethtool_ioctl(struct net_device* dev, struct ifreq *ifr);static int e100_set_config(struct net_device* dev, struct ifmap* map);static void e100_tx_timeout(struct net_device *dev);static struct net_device_stats *e100_get_stats(struct net_device *dev);static void set_multicast_list(struct net_device *dev);static void e100_hardware_send_packet(char *buf, int length);static void update_rx_stats(struct net_device_stats *);static void update_tx_stats(struct net_device_stats *);static int e100_probe_transceiver(void);static void e100_check_speed(unsigned long dummy);static void e100_set_speed(unsigned long speed);static void e100_check_duplex(unsigned long dummy);static void e100_set_duplex(enum duplex);static void e100_negotiate(void);static unsigned short e100_get_mdio_reg(unsigned char reg_num);static void e100_set_mdio_reg(unsigned char reg, unsigned short data);static void e100_send_mdio_cmd(unsigned short cmd, int write_cmd);static void e100_send_mdio_bit(unsigned char bit);static unsigned char e100_receive_mdio_bit(void);static void e100_reset_transceiver(void);static void e100_clear_network_leds(unsigned long dummy);static void e100_set_network_leds(int active);static void broadcom_check_speed(void);static void broadcom_check_duplex(void);static void tdk_check_speed(void);static void tdk_check_duplex(void);static void generic_check_speed(void);static void generic_check_duplex(void);struct transceiver_ops transceivers[] ={	{0x1018, broadcom_check_speed, broadcom_check_duplex},  /* Broadcom */	{0xC039, tdk_check_speed, tdk_check_duplex},            /* TDK 2120 */	{0x039C, tdk_check_speed, tdk_check_duplex},            /* TDK 2120C */	{0x0000, generic_check_speed, generic_check_duplex}     /* Generic, must be last */};#define tx_done(dev) (*R_DMA_CH0_CMD == 0)/* * Check for a network adaptor of this type, and return '0' if one exists.

⌨️ 快捷键说明

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