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

📄 lasi_82596.c

📁 讲述linux的初始化过程
💻 C
📖 第 1 页 / 共 3 页
字号:
/* lasi_82596.c -- driver for the intel 82596 ethernet controller, as   munged into HPPA boxen .   This driver is based upon 82596.c, original credits are below...   but there were too many hoops which HP wants jumped through to   keep this code in there in a sane manner.   3 primary sources of the mess --    1) hppa needs *lots* of cacheline flushing to keep this kind of   MMIO running.   2) The 82596 needs to see all of its pointers as their physical   address.  Thus virt_to_bus/bus_to_virt are *everywhere*.   3) The implementation HP is using seems to be significantly pickier    about when and how the command and RX units are started.  some   command ordering was changed.   Examination of the mach driver leads one to believe that there   might be a saner way to pull this off...  anyone who feels like a   full rewrite can be my guest.   Split 02/13/2000 Sam Creasey (sammy@oh.verio.com)      02/01/2000  Initial modifications for parisc by Helge Deller (deller@gmx.de)   03/02/2000  changes for better/correct(?) cache-flushing (deller)*//* 82596.c: A generic 82596 ethernet driver for linux. *//*   Based on Apricot.c   Written 1994 by Mark Evans.   This driver is for the Apricot 82596 bus-master interface   Modularised 12/94 Mark Evans   Modified to support the 82596 ethernet chips on 680x0 VME boards.   by Richard Hirst <richard@sleepie.demon.co.uk>   Renamed to be 82596.c   980825:  Changed to receive directly in to sk_buffs which are   allocated at open() time.  Eliminates copy on incoming frames   (small ones are still copied).  Shared data now held in a   non-cached page, so we can run on 68060 in copyback mode.   TBD:   * look at deferring rx frames rather than discarding (as per tulip)   * handle tx ring full as per tulip   * performace test to tune rx_copybreak   Most of my modifications relate to the braindead big-endian   implementation by Intel.  When the i596 is operating in   'big-endian' mode, it thinks a 32 bit value of 0x12345678   should be stored as 0x56781234.  This is a real pain, when   you have linked lists which are shared by the 680x0 and the   i596.   Driver skeleton   Written 1993 by Donald Becker.   Copyright 1993 United States Government as represented by the Director,   National Security Agency. This software may only be used and distributed   according to the terms of the GNU Public License as modified by SRC,   incorporated herein by reference.   The author may be reached as becker@super.org or   C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715 */static const char *version = "82596.c $Revision: 1.14 $\n";#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/ptrace.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/init.h>#include <linux/pci.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/pgtable.h>#include <asm/pgalloc.h>#include <asm/irq.h>#include <asm/pdc.h>#include <asm/gsc.h>#include <asm/cache.h>/* DEBUG flags */#define DEB_INIT	0x0001#define DEB_PROBE	0x0002#define DEB_SERIOUS	0x0004#define DEB_ERRORS	0x0008#define DEB_MULTI	0x0010#define DEB_TDR		0x0020#define DEB_OPEN	0x0040#define DEB_RESET	0x0080#define DEB_ADDCMD	0x0100#define DEB_STATUS	0x0200#define DEB_STARTTX	0x0400#define DEB_RXADDR	0x0800#define DEB_TXADDR	0x1000#define DEB_RXFRAME	0x2000#define DEB_INTS	0x4000#define DEB_STRUCT	0x8000#define DEB_ANY		0xffff#define DEB(x,y)	if (i596_debug & (x)) y#define  CHECK_WBACK(addr,len) \	do { if (!dma_consistent) dma_cache_wback((unsigned long)addr,len); } while (0)#define  CHECK_INV(addr,len) \	do { if (!dma_consistent) dma_cache_inv((unsigned long)addr,len); } while(0)#define  CHECK_WBACK_INV(addr,len) \	do { if (!dma_consistent) dma_cache_wback_inv((unsigned long)addr,len); } while (0)#define PA_I82596_RESET		0	/* Offsets relative to LASI-LAN-Addr.*/#define PA_CPU_PORT_L_ACCESS	4#define PA_CHANNEL_ATTENTION	8/* * Define various macros for Channel Attention, word swapping etc., dependent * on architecture.  MVME and BVME are 680x0 based, otherwise it is Intel. */#ifdef __BIG_ENDIAN#define WSWAPrfd(x)  ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))#define WSWAPrbd(x)  ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))#define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))#define WSWAPscb(x)  ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))#define WSWAPcmd(x)  ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))#define WSWAPtbd(x)  ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))#define WSWAPchar(x) ((char *)            (((u32)(x)<<16) | ((((u32)(x)))>>16)))#define ISCP_BUSY	0x00010000#define MACH_IS_APRICOT	0#else#define WSWAPrfd(x)     ((struct i596_rfd *)(x))#define WSWAPrbd(x)     ((struct i596_rbd *)(x))#define WSWAPiscp(x)    ((struct i596_iscp *)(x))#define WSWAPscb(x)     ((struct i596_scb *)(x))#define WSWAPcmd(x)     ((struct i596_cmd *)(x))#define WSWAPtbd(x)     ((struct i596_tbd *)(x))#define WSWAPchar(x)    ((char *)(x))#define ISCP_BUSY	0x0001#define MACH_IS_APRICOT	1#endif/* * The MPU_PORT command allows direct access to the 82596. With PORT access * the following commands are available (p5-18). The 32-bit port command * must be word-swapped with the most significant word written first. * This only applies to VME boards. */#define PORT_RESET		0x00	/* reset 82596 */#define PORT_SELFTEST		0x01	/* selftest */#define PORT_ALTSCP		0x02	/* alternate SCB address */#define PORT_ALTDUMP		0x03	/* Alternate DUMP address */static int i596_debug = (DEB_SERIOUS|DEB_PROBE);  MODULE_AUTHOR("Richard Hirst");MODULE_DESCRIPTION("i82596 driver");MODULE_PARM(i596_debug, "i");/* Copy frames shorter than rx_copybreak, otherwise pass on up in * a full sized sk_buff.  Value of 100 stolen from tulip.c (!alpha). */static int rx_copybreak = 100;#define PKT_BUF_SZ	1536#define MAX_MC_CNT	64#define I596_TOTAL_SIZE 17#define I596_NULL ((void *)0xffffffff)#define CMD_EOL		0x8000	/* The last command of the list, stop. */#define CMD_SUSP	0x4000	/* Suspend after doing cmd. */#define CMD_INTR	0x2000	/* Interrupt after doing cmd. */#define CMD_FLEX	0x0008	/* Enable flexible memory model */enum commands {	CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,	CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};#define STAT_C		0x8000	/* Set to 0 after execution */#define STAT_B		0x4000	/* Command being executed */#define STAT_OK		0x2000	/* Command executed ok */#define STAT_A		0x1000	/* Command aborted */#define	 CUC_START	0x0100#define	 CUC_RESUME	0x0200#define	 CUC_SUSPEND    0x0300#define	 CUC_ABORT	0x0400#define	 RX_START	0x0010#define	 RX_RESUME	0x0020#define	 RX_SUSPEND	0x0030#define	 RX_ABORT	0x0040#define TX_TIMEOUT	5#define OPT_SWAP_PORT	0x0001	/* Need to wordswp on the MPU port */struct i596_reg {	unsigned short porthi;	unsigned short portlo;	unsigned long ca;};#define EOF		0x8000#define SIZE_MASK	0x3fffstruct i596_tbd {	unsigned short size;	unsigned short pad;	struct i596_tbd *next;	char *data;	long cache_pad[5];		/* Total 32 bytes... */};/* The command structure has two 'next' pointers; v_next is the address of * the next command as seen by the CPU, b_next is the address of the next * command as seen by the 82596.  The b_next pointer, as used by the 82596 * always references the status field of the next command, rather than the * v_next field, because the 82596 is unaware of v_next.  It may seem more * logical to put v_next at the end of the structure, but we cannot do that * because the 82596 expects other fields to be there, depending on command * type. */struct i596_cmd {	struct i596_cmd *v_next;	/* Address from CPUs viewpoint */	unsigned short status;	unsigned short command;	struct i596_cmd *b_next;	/* Address from i596 viewpoint */};struct tx_cmd {	struct i596_cmd cmd;	struct i596_tbd *tbd;	unsigned short size;	unsigned short pad;	struct sk_buff *skb;		/* So we can free it after tx */	dma_addr_t dma_addr;	long cache_pad[1];		/* Total 32 bytes... */};struct tdr_cmd {	struct i596_cmd cmd;	unsigned short status;	unsigned short pad;};struct mc_cmd {	struct i596_cmd cmd;	short mc_cnt;	char mc_addrs[MAX_MC_CNT*6];};struct sa_cmd {	struct i596_cmd cmd;	char eth_addr[8];};struct cf_cmd {	struct i596_cmd cmd;	char i596_config[16];};struct i596_rfd {	unsigned short stat;	unsigned short cmd;	struct i596_rfd *b_next;	/* Address from i596 viewpoint */	struct i596_rbd *rbd;	unsigned short count;	unsigned short size;	struct i596_rfd *v_next;	/* Address from CPUs viewpoint */	struct i596_rfd *v_prev;	long cache_pad[2];		/* Total 32 bytes... */};struct i596_rbd {    unsigned short count;    unsigned short zero1;    struct i596_rbd *b_next;    unsigned char *b_data;		/* Address from i596 viewpoint */    unsigned short size;    unsigned short zero2;    struct sk_buff *skb;    struct i596_rbd *v_next;    struct i596_rbd *b_addr;		/* This rbd addr from i596 view */    unsigned char *v_data;		/* Address from CPUs viewpoint */					/* Total 32 bytes... */};/* These values as chosen so struct i596_private fits in one page... */#define TX_RING_SIZE 32#define RX_RING_SIZE 16struct i596_scb {	unsigned short status;	unsigned short command;	struct i596_cmd *cmd;	struct i596_rfd *rfd;	unsigned long crc_err;	unsigned long align_err;	unsigned long resource_err;	unsigned long over_err;	unsigned long rcvdt_err;	unsigned long short_err;	unsigned short t_on;	unsigned short t_off;};struct i596_iscp {	unsigned long stat;	struct i596_scb *scb;};struct i596_scp {	unsigned long sysbus;	unsigned long pad;	struct i596_iscp *iscp;};struct i596_private {	volatile struct i596_scp scp		__attribute__((aligned(32)));	volatile struct i596_iscp iscp		__attribute__((aligned(32)));	volatile struct i596_scb scb		__attribute__((aligned(32)));	struct sa_cmd sa_cmd			__attribute__((aligned(32)));	struct cf_cmd cf_cmd			__attribute__((aligned(32)));	struct tdr_cmd tdr_cmd			__attribute__((aligned(32)));	struct mc_cmd mc_cmd			__attribute__((aligned(32)));	struct i596_rfd rfds[RX_RING_SIZE]	__attribute__((aligned(32)));	struct i596_rbd rbds[RX_RING_SIZE]	__attribute__((aligned(32)));	struct tx_cmd tx_cmds[TX_RING_SIZE]	__attribute__((aligned(32)));	struct i596_tbd tbds[TX_RING_SIZE]	__attribute__((aligned(32)));	unsigned long stat;	int last_restart;	struct i596_rfd *rfd_head;	struct i596_rbd *rbd_head;	struct i596_cmd *cmd_tail;	struct i596_cmd *cmd_head;	int cmd_backlog;	unsigned long last_cmd;	struct net_device_stats stats;	int next_tx_cmd;	int options;	spinlock_t lock;	dma_addr_t dma_addr;};char init_setup[] ={	0x8E,			/* length, prefetch on */	0xC8,			/* fifo to 8, monitor off */	0x80,			/* don't save bad frames */	0x2E,			/* No source address insertion, 8 byte preamble */	0x00,			/* priority and backoff defaults */	0x60,			/* interframe spacing */	0x00,			/* slot time LSB */	0xf2,			/* slot time and retries */	0x00,			/* promiscuous mode */	0x00,			/* collision detect */	0x40,			/* minimum frame length */	0xff,	0x00,	0x7f /*  *multi IA */ };static int dma_consistent = 1;	/* Zero if pci_alloc_consistent() fails */static int i596_open(struct net_device *dev);static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs);static int i596_close(struct net_device *dev);static struct net_device_stats *i596_get_stats(struct net_device *dev);static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);static void i596_tx_timeout (struct net_device *dev);static void print_eth(unsigned char *buf, char *str);static void set_multicast_list(struct net_device *dev);static int rx_ring_size = RX_RING_SIZE;static int ticks_limit = 100;static int max_cmd_backlog = TX_RING_SIZE-1;static inline void CA(struct net_device *dev){	gsc_writel(0, (void*)(dev->base_addr + PA_CHANNEL_ATTENTION));}static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x){	struct i596_private *lp = (struct i596_private *) dev->priv;	u32 v = (u32) (c) | (u32) (x);	if (lp->options & OPT_SWAP_PORT)		v = ((u32) (v) << 16) | ((u32) (v) >> 16);	gsc_writel(v & 0xffff, (void*)(dev->base_addr + PA_CPU_PORT_L_ACCESS));	udelay(1);	gsc_writel(v >> 16,    (void*)(dev->base_addr + PA_CPU_PORT_L_ACCESS));}static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str){	CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));	while (--delcnt && lp->iscp.stat) {		udelay(10);		CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));	}	if (!delcnt) {		printk("%s: %s, iscp.stat %04lx, didn't clear\n",		     dev->name, str, lp->iscp.stat);		return -1;	}	else		return 0;}static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str){	CHECK_INV(&(lp->scb), sizeof(struct i596_scb));	while (--delcnt && lp->scb.command) {		udelay(10);		CHECK_INV(&(lp->scb), sizeof(struct i596_scb));	}	if (!delcnt) {		printk("%s: %s, status %4.4x, cmd %4.4x.\n",		     dev->name, str, lp->scb.status, lp->scb.command);		return -1;	}	else		return 0;}static void i596_display_data(struct net_device *dev){	struct i596_private *lp = (struct i596_private *) dev->priv;	struct i596_cmd *cmd;	struct i596_rfd *rfd;	struct i596_rbd *rbd;	printk("lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",	       &lp->scp, lp->scp.sysbus, lp->scp.iscp);	printk("iscp at %p, iscp.stat = %08lx, .scb = %p\n",	       &lp->iscp, lp->iscp.stat, lp->iscp.scb);	printk("scb at %p, scb.status = %04x, .command = %04x,"		" .cmd = %p, .rfd = %p\n",	       &lp->scb, lp->scb.status, lp->scb.command,		lp->scb.cmd, lp->scb.rfd);	printk("   errors: crc %lx, align %lx, resource %lx,"               " over %lx, rcvdt %lx, short %lx\n",		lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,		lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);	cmd = lp->cmd_head;	while (cmd != I596_NULL) {		printk("cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",		  cmd, cmd->status, cmd->command, cmd->b_next);		cmd = cmd->v_next;	}	rfd = lp->rfd_head;	printk("rfd_head = %p\n", rfd);	do {		printk ("   %p .stat %04x, .cmd %04x, b_next %p, rbd %p,"                        " count %04x\n",			rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,			rfd->count);		rfd = rfd->v_next;	} while (rfd != lp->rfd_head);	rbd = lp->rbd_head;	printk("rbd_head = %p\n", rbd);	do {		printk("   %p .count %04x, b_next %p, b_data %p, size %04x\n",			rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);		rbd = rbd->v_next;	} while (rbd != lp->rbd_head);	CHECK_INV(lp, sizeof(struct i596_private));}#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)static void i596_error(int irq, void *dev_id, struct pt_regs *regs){	struct net_device *dev = dev_id;	volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;	pcc2[0x28] = 1;

⌨️ 快捷键说明

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