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

📄 3c574_cs.c

📁 h内核
💻 C
📖 第 1 页 / 共 3 页
字号:
/* 3c574.c: A PCMCIA ethernet driver for the 3com 3c574 "RoadRunner".	Written 1993-1998 by	Donald Becker, becker@scyld.com, (driver core) and	David Hinds, dahinds@users.sourceforge.net (from his PC card code).	Locking fixes (C) Copyright 2003 Red Hat Inc	This software may be used and distributed according to the terms of	the GNU General Public License, incorporated herein by reference.	This driver derives from Donald Becker's 3c509 core, which has the	following copyright:	Copyright 1993 United States Government as represented by the	Director, National Security Agency.	*//*				Theory of OperationI. Board CompatibilityThis device driver is designed for the 3Com 3c574 PC card Fast EthernetAdapter.II. Board-specific settingsNone -- PC cards are autoconfigured.III. Driver operationThe 3c574 uses a Boomerang-style interface, without the bus-master capability.See the Boomerang driver and documentation for most details.IV. Notes and chip documentation.Two added registers are used to enhance PIO performance, RunnerRdCtrl andRunnerWrCtrl.  These are 11 bit down-counters that are preloaded with thecount of word (16 bits) reads or writes the driver is about to do to the Rxor Tx FIFO.  The chip is then able to hide the internal-PCI-bus to PC-cardtranslation latency by buffering the I/O operations with an 8 word FIFO.Note: No other chip accesses are permitted when this buffer is used.A second enhancement is that both attribute and common memory space0x0800-0x0fff can translated to the PIO FIFO.  Thus memory operations (fasterwith *some* PCcard bridges) may be used instead of I/O operations.This is enabled by setting the 0x10 bit in the PCMCIA LAN COR.Some slow PC card bridges work better if they never see a WAIT signal.This is configured by setting the 0x20 bit in the PCMCIA LAN COR.Only do this after testing that it is reliable and improves performance.The upper five bits of RunnerRdCtrl are used to window into PCcardconfiguration space registers.  Window 0 is the regular Boomerang/Odieregister set, 1-5 are various PC card control registers, and 16-31 arethe (reversed!) CIS table.A final note: writing the InternalConfig register in window 3 with aninvalid ramWidth is Very Bad.V. Referenceshttp://www.scyld.com/expert/NWay.htmlhttp://www.national.com/pf/DP/DP83840.htmlThanks to Terry Murphy of 3Com for providing development information forearlier 3Com products.*/#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/interrupt.h>#include <linux/in.h>#include <linux/delay.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/if_arp.h>#include <linux/ioport.h>#include <linux/ethtool.h>#include <linux/bitops.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/cisreg.h>#include <pcmcia/ciscode.h>#include <pcmcia/ds.h>#include <pcmcia/mem_op.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/system.h>/*====================================================================*//* Module parameters */MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");MODULE_DESCRIPTION("3Com 3c574 series PCMCIA ethernet driver");MODULE_LICENSE("GPL");#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)/* Maximum events (Rx packets, etc.) to handle at each interrupt. */INT_MODULE_PARM(max_interrupt_work, 32);/* Force full duplex modes? */INT_MODULE_PARM(full_duplex, 0);/* Autodetect link polarity reversal? */INT_MODULE_PARM(auto_polarity, 1);#ifdef PCMCIA_DEBUGINT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static char *version ="3c574_cs.c 1.65ac1 2003/04/07 Donald Becker/David Hinds, becker@scyld.com.\n";#else#define DEBUG(n, args...)#endif/*====================================================================*//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT  ((800*HZ)/1000)/* To minimize the size of the driver source and make the driver more   readable not all constants are symbolically defined.   You'll need the manual if you want to understand driver details anyway. *//* Offsets from base I/O address. */#define EL3_DATA	0x00#define EL3_CMD		0x0e#define EL3_STATUS	0x0e#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)/* The top five bits written to EL3_CMD are a command, the lower   11 bits are the parameter, if applicable. */enum el3_cmds {	TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,	RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,	TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,	FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,	SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,	SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,	StatsDisable = 22<<11, StopCoax = 23<<11,};enum elxl_status {	IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,	TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,	IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000 };/* The SetRxFilter command accepts the following classes: */enum RxFilter {	RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8};enum Window0 {	Wn0EepromCmd = 10, Wn0EepromData = 12, /* EEPROM command/address, data. */	IntrStatus=0x0E,		/* Valid in all windows. */};/* These assumes the larger EEPROM. */enum Win0_EEPROM_cmds {	EEPROM_Read = 0x200, EEPROM_WRITE = 0x100, EEPROM_ERASE = 0x300,	EEPROM_EWENB = 0x30,		/* Enable erasing/writing for 10 msec. */	EEPROM_EWDIS = 0x00,		/* Disable EWENB before 10 msec timeout. */};/* Register window 1 offsets, the window used in normal operation.   On the "Odie" this window is always mapped at offsets 0x10-0x1f.   Except for TxFree, which is overlapped by RunnerWrCtrl. */enum Window1 {	TX_FIFO = 0x10,  RX_FIFO = 0x10,  RxErrors = 0x14,	RxStatus = 0x18,  Timer=0x1A, TxStatus = 0x1B,	TxFree = 0x0C, /* Remaining free bytes in Tx buffer. */	RunnerRdCtrl = 0x16, RunnerWrCtrl = 0x1c,};enum Window3 {			/* Window 3: MAC/config bits. */	Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,};union wn3_config {	int i;	struct w3_config_fields {		unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2;		int pad8:8;		unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1, autoselect:1;		int pad24:7;	} u;};enum Window4 {		/* Window 4: Xcvr/media bits. */	Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,};#define MEDIA_TP	0x00C0	/* Enable link beat and jabber for 10baseT. */struct el3_private {	dev_link_t link;	dev_node_t node;	struct net_device_stats stats;	u16 advertising, partner;		/* NWay media advertisement */	unsigned char phys;			/* MII device address */	unsigned int autoselect:1, default_media:3;	/* Read from the EEPROM/Wn3_Config. */	/* for transceiver monitoring */	struct timer_list media;	unsigned short media_status;	unsigned short fast_poll;	unsigned long last_irq;	spinlock_t window_lock;			/* Guards the Window selection */};/* Set iff a MII transceiver on any interface requires mdio preamble.   This only set with the original DP83840 on older 3c905 boards, so the extra   code size of a per-interface flag is not worthwhile. */static char mii_preamble_required = 0;/* Index of functions. */static void tc574_config(dev_link_t *link);static void tc574_release(dev_link_t *link);static int tc574_event(event_t event, int priority,					   event_callback_args_t *args);static void mdio_sync(kio_addr_t ioaddr, int bits);static int mdio_read(kio_addr_t ioaddr, int phy_id, int location);static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value);static unsigned short read_eeprom(kio_addr_t ioaddr, int index);static void tc574_wait_for_completion(struct net_device *dev, int cmd);static void tc574_reset(struct net_device *dev);static void media_check(unsigned long arg);static int el3_open(struct net_device *dev);static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void update_stats(struct net_device *dev);static struct net_device_stats *el3_get_stats(struct net_device *dev);static int el3_rx(struct net_device *dev, int worklimit);static int el3_close(struct net_device *dev);static void el3_tx_timeout(struct net_device *dev);static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static struct ethtool_ops netdev_ethtool_ops;static void set_rx_mode(struct net_device *dev);static dev_info_t dev_info = "3c574_cs";static dev_link_t *tc574_attach(void);static void tc574_detach(dev_link_t *);static dev_link_t *dev_list;/*	tc574_attach() creates an "instance" of the driver, allocating	local data structures for one device.  The device is registered	with Card Services.*/static dev_link_t *tc574_attach(void){	struct el3_private *lp;	client_reg_t client_reg;	dev_link_t *link;	struct net_device *dev;	int ret;	DEBUG(0, "3c574_attach()\n");	/* Create the PC card device object. */	dev = alloc_etherdev(sizeof(struct el3_private));	if (!dev)		return NULL;	lp = netdev_priv(dev);	link = &lp->link;	link->priv = dev;	spin_lock_init(&lp->window_lock);	link->io.NumPorts1 = 32;	link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;	link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;	link->irq.IRQInfo1 = IRQ_LEVEL_ID;	link->irq.Handler = &el3_interrupt;	link->irq.Instance = dev;	link->conf.Attributes = CONF_ENABLE_IRQ;	link->conf.Vcc = 50;	link->conf.IntType = INT_MEMORY_AND_IO;	link->conf.ConfigIndex = 1;	link->conf.Present = PRESENT_OPTION;	/* The EL3-specific entries in the device structure. */	dev->hard_start_xmit = &el3_start_xmit;	dev->get_stats = &el3_get_stats;	dev->do_ioctl = &el3_ioctl;	SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);	dev->set_multicast_list = &set_rx_mode;	dev->open = &el3_open;	dev->stop = &el3_close;#ifdef HAVE_TX_TIMEOUT	dev->tx_timeout = el3_tx_timeout;	dev->watchdog_timeo = TX_TIMEOUT;#endif	/* Register with Card Services */	link->next = dev_list;	dev_list = link;	client_reg.dev_info = &dev_info;	client_reg.EventMask =		CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |			CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |				CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;	client_reg.event_handler = &tc574_event;	client_reg.Version = 0x0210;	client_reg.event_callback_args.client_data = link;	ret = pcmcia_register_client(&link->handle, &client_reg);	if (ret != 0) {		cs_error(link->handle, RegisterClient, ret);		tc574_detach(link);		return NULL;	}	return link;} /* tc574_attach *//*	This deletes a driver "instance".  The device is de-registered	with Card Services.  If it has been released, all local data	structures are freed.  Otherwise, the structures will be freed	when the device is released.*/static void tc574_detach(dev_link_t *link){	struct net_device *dev = link->priv;	dev_link_t **linkp;	DEBUG(0, "3c574_detach(0x%p)\n", link);	/* Locate device structure */	for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)		if (*linkp == link) break;	if (*linkp == NULL)		return;	if (link->dev)		unregister_netdev(dev);	if (link->state & DEV_CONFIG)		tc574_release(link);	if (link->handle)		pcmcia_deregister_client(link->handle);	/* Unlink device structure, free bits */	*linkp = link->next;	free_netdev(dev);} /* tc574_detach *//*	tc574_config() is scheduled to run after a CARD_INSERTION event	is received, to configure the PCMCIA socket, and to make the	ethernet device available to the system.*/#define CS_CHECK(fn, ret) \  do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)static char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};static void tc574_config(dev_link_t *link){	client_handle_t handle = link->handle;	struct net_device *dev = link->priv;	struct el3_private *lp = netdev_priv(dev);	tuple_t tuple;	cisparse_t parse;	unsigned short buf[32];	int last_fn, last_ret, i, j;	kio_addr_t ioaddr;	u16 *phys_addr;	char *cardname;	union wn3_config config;	phys_addr = (u16 *)dev->dev_addr;	DEBUG(0, "3c574_config(0x%p)\n", link);	tuple.Attributes = 0;	tuple.DesiredTuple = CISTPL_CONFIG;	CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));	tuple.TupleData = (cisdata_t *)buf;	tuple.TupleDataMax = 64;	tuple.TupleOffset = 0;	CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));	CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));	link->conf.ConfigBase = parse.config.base;	link->conf.Present = parse.config.rmask[0];	/* Configure card */	link->state |= DEV_CONFIG;	link->io.IOAddrLines = 16;	for (i = j = 0; j < 0x400; j += 0x20) {		link->io.BasePort1 = j ^ 0x300;		i = pcmcia_request_io(link->handle, &link->io);		if (i == CS_SUCCESS) break;	}	if (i != CS_SUCCESS) {		cs_error(link->handle, RequestIO, i);		goto failed;	}	CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));	CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));	dev->irq = link->irq.AssignedIRQ;	dev->base_addr = link->io.BasePort1;	ioaddr = dev->base_addr;	/* The 3c574 normally uses an EEPROM for configuration info, including	   the hardware address.  The future products may include a modem chip	   and put the address in the CIS. */	tuple.DesiredTuple = 0x88;	if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) {		pcmcia_get_tuple_data(handle, &tuple);		for (i = 0; i < 3; i++)			phys_addr[i] = htons(buf[i]);

⌨️ 快捷键说明

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