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

📄 smc91111.c

📁 smc9111网卡芯片的linux驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/*------------------------------------------------------------------------ . smc91111.c . This is a driver for SMSC's 91C111 single-chip Ethernet device. . . Copyright (C) 2001 Standard Microsystems Corporation (SMSC) .       Developed by Simple Network Magic Corporation (SNMC) . Copyright (C) 1996 by Erik Stahlman (ES) . . 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 . . Information contained in this file was obtained from the LAN91C111 . manual from SMC.  To get a copy, if you really want one, you can find  . information under www.smsc.com. .  . . "Features" of the SMC chip: .   Integrated PHY/MAC for 10/100BaseT Operation .   Supports internal and external MII .   Integrated 8K packet memory .   EEPROM interface for configuration . . Arguments: . 	io	= for the base address .	irq	= for the IRQ .	nowait	= 0 for normal wait states, 1 eliminates additional wait states . . author: . 	Erik Stahlman				( erik@vt.edu ) . 	Daris A Nevil				( dnevil@snmc.com ) .  	Pramod B Bhardwaj   			(pramod.bhardwaj@smsc.com) . . . Hardware multicast code from Peter Cammaert ( pc@denkart.be ) . . Sources: .    o   SMSC LAN91C111 databook (www.smsc.com) .    o   smc9194.c by Erik Stahlman .    o   skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov ) . . History: .    12/20/01	Jeff Sutherland <jeffs@accelent.com>, ported to ARM Xscale proc. .    09/24/01  Pramod B Bhardwaj, Added the changes for Kernel 2.4 .    08/21/01  Pramod B Bhardwaj Added support for RevB of LAN91C111 .	04/25/01  Daris A Nevil  Initial public release through SMSC .	03/16/01  Daris A Nevil  Modified smc9194.c for use with LAN91C111  ----------------------------------------------------------------------------*/static const char version[] =    "SMSC LAN91C111 Driver (v2.1), (Linux Kernel 2.4 + Support for Odd Byte) 09/24/01\nby Pramod Bhardwaj (pramod.bhardwaj@smsc.com)\n\n";#include <linux/config.h>#include <linux/module.h>#include <linux/version.h>#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/slab.h>#include <linux/string.h>#include <linux/init.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/irq.h>#include <linux/errno.h>#include <linux/delay.h>#include <asm/hardware.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/pci.h>#include <asm/dma.h>#ifdef CONFIG_SYSCTL#include <linux/proc_fs.h>#include <linux/sysctl.h>#endif/*#undef SMC_DEBUG		// May be defined in makefile*/#define SMC_DEBUG 0#include "smc91111.h"#include "smc91111_cfg.h"	//provides localization for driver#include </kernel2.6/linux-2.6.14/include/asm-arm/arch-s3c2410/regs-mem.h>#include </kernel2.6/linux-2.6.14/include/asm-arm/arch-s3c2410/regs-gpio.h>#include </kernel2.6/linux-2.6.14/include/asm-arm/arch-s3c2410/irqs.h>/* * Define to use AUTO_RELEASE for transmit packets. This will  * release the allocated memory automatically upon successful * transmission. At least in theory... * During heavy transmit loads the MMU seems to get confused * and it takes down the transmit and receive FIFOs with it. * The data register will return a single dword (upper 16 * bits 0) no matter which address was selected. Since the * upper word is zero, the byte count will be zero resulting * in a "Received Packet Size TOO Small" error. At that point * only a reset will restore order :( * ## WARNING: Use at your own risk ##  *///#define USE_AUTO_RELEASE 1    /* . DEBUGGING LEVELS . . 0 for normal operation . 1 for slightly more details . >2 for various levels of increasingly useless information .    2 for interrupt tracking, status flags .    3 for packet info .    4 for complete packet dumps*/#if (SMC_DEBUG > 3 )#define PRINTK3(args...) printk(args)#else#define PRINTK3(args...)#endif#if SMC_DEBUG > 2#define PRINTK2(args...) printk(args)#else#define PRINTK2(args...)#endif#ifdef SMC_DEBUG > 1#define PRINTK(args...) printk(args)#else#define PRINTK(args...)#endif/*------------------------------------------------------------------------ . . The internal workings of the driver.  If you are changing anything . here with the SMC stuff, you should have the datasheet and know . what you are doing. . -------------------------------------------------------------------------*/#define CARDNAME "LAN91C111"// Memory sizing constant// This will be dynamic, in hunks of 128, on the 91C112 :-)#define LAN91C111_MEMORY_MULTIPLIER	(1024*2)/* a hack to fix a kludge :\ */static int wait_mode[MAX_NETWORK_INTERFACE_COUNT];void lan91c111Reset(void);/* store this information for the driver.. */struct smc_local {	// these are things that the kernel wants me to keep, so users	// can find out semi-useless statistics of how well the card is	// performing	struct net_device_stats stats;	// If I have to wait until memory is available to send	// a packet, I will store the skbuff here, until I get the	// desired memory.  Then, I'll send it out and free it.	struct sk_buff *saved_skb;	// This keeps track of how many packets that I have	// sent out.  When an TX_EMPTY interrupt comes, I know	// that all of these have been sent.	int packets_waiting;	// keep track of tx byte count for packets that have been	// sent to the tx-queue but haven't received an interrupt	// indicating they've left the chip.	unsigned int tx_bytes;	// Set to true during the auto-negotiation sequence	int autoneg_active;	// Address of our PHY port	u16 phyaddr;	// Type of PHY	u16 phytype;	// Last contents of PHY Register 18	u16 lastPhy18;	// Contains the current active transmission mode	u16 tcr_cur_mode;	// Contains the current active receive mode	u16 rcr_cur_mode;	// Contains the current active receive/phy mode	u16 rpc_cur_mode;        spinlock_t mmu_lock;	/* => Pramod, Odd Byte issue */	// Contains the Current ChipID	unsigned short ChipID;	//Contains the Current ChipRevision	unsigned short ChipRev;	/* <= Pramod, Odd Byte issue */	// JWS- DMA support:	unsigned long dev_dma_phys;	int use_32bit;#ifdef CONFIG_SYSCTL	// Root directory /proc/sys/dev	// Second entry must be null to terminate the table	ctl_table root_table[2];	// Directory for this device /proc/sys/dev/ethX	// Again the second entry must be zero to terminate	ctl_table eth_table[2];	// This is the parameters (file) table	ctl_table param_table[CTL_SMC_LAST_ENTRY];	// Saves the sysctl header returned by register_sysctl_table()	// we send this to unregister_sysctl_table()	struct ctl_table_header *sysctl_header;	// Parameter variables (files) go here	char ctl_info[1024];	int ctl_swfdup;	int ctl_ephloop;	int ctl_miiop;	int ctl_autoneg;	int ctl_rfduplx;	int ctl_rspeed;	int ctl_afduplx;	int ctl_aspeed;	int ctl_lnkfail;	int ctl_forcol;	int ctl_filtcar;	int ctl_freemem;	int ctl_totmem;	int ctl_leda;	int ctl_ledb;	int ctl_chiprev;#ifdef SMC_DEBUG	int ctl_reg_bsr;	int ctl_reg_tcr;	int ctl_reg_esr;	int ctl_reg_rcr;	int ctl_reg_ctrr;	int ctl_reg_mir;	int ctl_reg_rpcr;	int ctl_reg_cfgr;	int ctl_reg_bar;	int ctl_reg_iar0;	int ctl_reg_iar1;	int ctl_reg_iar2;	int ctl_reg_gpr;	int ctl_reg_ctlr;	int ctl_reg_mcr;	int ctl_reg_pnr;	int ctl_reg_fpr;	int ctl_reg_ptr;	int ctl_reg_dr;	int ctl_reg_isr;	int ctl_reg_mtr1;	int ctl_reg_mtr2;	int ctl_reg_mtr3;	int ctl_reg_mtr4;	int ctl_reg_miir;	int ctl_reg_revr;	int ctl_reg_ercvr;	int ctl_reg_extr;	int ctl_phy_ctrl;	int ctl_phy_stat;	int ctl_phy_id1;	int ctl_phy_id2;	int ctl_phy_adc;	int ctl_phy_remc;	int ctl_phy_cfg1;	int ctl_phy_cfg2;	int ctl_phy_int;	int ctl_phy_mask;#endif				// SMC_DEBUG#endif				// CONFIG_SYSCTL};/*----------------------------------------------------------------- . .  The driver can be entered at any of the following entry points. . .------------------------------------------------------------------  *//* . This is called by  register_netdev().  It is responsible for . checking the portlist for the SMC9000 series chipset.  If it finds . one, then it will initialize the device, find the hardware information, . and sets up the appropriate device parameters. . NOTE: Interrupts are *OFF* when this procedure is called. . . NB:This shouldn't be static since it is referred to externally.*/int smc_init(struct net_device *dev);/* . This is called by  unregister_netdev().  It is responsible for . cleaning up before the driver is finally unregistered and discarded.*/void smc_destructor(struct net_device *dev);/* . The kernel calls this function when someone wants to use the net_device, . typically 'ifconfig ethX up'.*/static int smc_open(struct net_device *dev);/* . This is called by the kernel to send a packet out into the net.  it's . responsible for doing a best-effort send, but if it's simply not possible . to send it, the packet gets dropped.*/static void smc_timeout(struct net_device *dev);/* . This is called by the kernel in response to 'ifconfig ethX down'.  It . is responsible for cleaning up everything that the open routine . does, and maybe putting the card into a powerdown state.*/static int smc_close(struct net_device *dev);/* . This routine allows the proc file system to query the driver's . statistics.*/static struct net_device_stats *smc_query_statistics(struct net_device *dev);/* . Finally, a call to set promiscuous mode ( for TCPDUMP and related . programs ) and multicast modes.*/static void smc_set_multicast_list(struct net_device *dev);/* . Configures the PHY through the MII Management interface*/static void smc_phy_configure(struct net_device *dev);/*--------------------------------------------------------------- . . Interrupt level calls.. . ----------------------------------------------------------------*//* * handles dma irq for receive */static void smc_dma_irq(int ch, void *lp, struct pt_regs *regs);/* . Handles chip's interrupt*/static void smc_interrupt(int irq, void *, struct pt_regs *regs);/* . This is a separate procedure to handle the receipt of a packet, to . leave the interrupt code looking slightly cleaner*/inline static void smc_rcv(struct net_device *dev);/* . This handles a TX interrupt, which is called when an error . relating to a packet is sent or for single TX mode  . (non-AUTO_RELEASE).*/inline static void smc_tx(struct net_device *dev);/* . This handles interrupts generated from PHY register 18*/static void smc_phy_interrupt(struct net_device *dev);/* ------------------------------------------------------------ . . Internal routines . ------------------------------------------------------------*//* . Test if a given location contains a chip, trying to cause as . little damage as possible if it's not a SMC chip.*/static int smc_probe(struct net_device *dev, unsigned int ioaddr);/* . A rather simple routine to print out a packet for debugging purposes.*/#if SMC_DEBUG > 2static void print_packet(u8 *, int);#endif#define tx_done(dev) 1/* this is called to actually send the packet to the chip */static void smc_hardware_send_packet(struct net_device *dev);/* Since I am not sure if I will have enough room in the chip's ram . to store the packet, I call this routine, which either sends it . now, or generates an interrupt when the card is ready for the . packet */static int smc_wait_to_send_packet(struct sk_buff *skb, struct net_device *dev);/* this does a soft reset on the device */static void smc_reset(struct net_device *dev);/* Enable Interrupts, Receive, and Transmit */static void smc_enable(struct net_device *dev);/* this puts the device in an inactive state */static void smc_shutdown(unsigned int ioaddr);#ifndef NO_AUTOPROBE/* This routine will find the IRQ of the driver if one is not . specified in the input to the device.  */static int smc_findirq(unsigned int ioaddr);#endif/*  this routine will set the hardware multicast table to the specified  values given it by the higher level routines*/static void smc_setmulticast(unsigned int ioaddr, int count,			     struct dev_mc_list *);static int crc32(char *, int);/* Routines to Read and Write the PHY Registers across the   MII Management Interface*/static u16 smc_read_phy_register(unsigned int ioaddr, u8 phyaddr,				  u8 phyreg);static void smc_write_phy_register(unsigned int ioaddr, u8 phyaddr,				   u8 phyreg, u16 phydata);/* Initilizes our device's sysctl proc filesystem */#ifdef CONFIG_SYSCTLstatic void smc_sysctl_register(struct net_device *);static void smc_sysctl_unregister(struct net_device *);#endif				/* CONFIG_SYSCTL */#ifdef CONFIG_ARCH_S3C2410/* * These functions allow us to handle IO addressing as we wish - this * ethernet controller can be connected to a variety of busses.  Some * busses do not support 16 bit or 32 bit transfers.  --rmk */static inline u8SMC_inb(u_int base, u_int reg)

⌨️ 快捷键说明

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