📄 82596.c
字号:
/* 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 *** Untested on Apricot hardware, and may require some hacking *** to make it work. The old 82596.c reported hasn't worked *** since 1.3.xx anyway. I have been unable to find any users *** of Apricot hardware to test this on. 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:v1.0 15/07/98\n";#include <linux/config.h>#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 <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <asm/pgtable.h> /*?? */#ifdef CONFIG_MVME16x_NET#include <asm/mvme16xhw.h>#endif#ifdef CONFIG_BVME6000_NET#include <asm/bvme6000hw.h>#endif/* * Define various macros for Channel Attention, word swapping etc., dependent * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel. */#ifdef __mc68000__#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) x#define WSWAPiscp(x) ((struct i596_iscp *)(x))#define WSWAPscb(x) ((struct i596_scb *)(x))#define WSWAPcmd(x) x#define WSWAPtbd(x) x#define WSWAPchar(x) 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 */#ifndef HAVE_PORTRESERVE#define check_region(addr, size) 0#define request_region(addr, size,name) do ; while(0)#endif#ifndef HAVE_ALLOC_SKB#define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)#define kfree_skbmem(buff, size) kfree_s(buff,size)#endif#define APRICOT_DEBUG 2#ifdef APRICOT_DEBUGint i596_debug = APRICOT_DEBUG;#elseint i596_debug = 1;#endif#define I596_TOTAL_SIZE 17#define I596_NULL -1#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 0x0040struct i596_reg { unsigned short porthi; unsigned short portlo; unsigned long ca;};struct i596_cmd { unsigned short status; unsigned short command; struct i596_cmd *next;};#define EOF 0x8000#define SIZE_MASK 0x3fffstruct i596_tbd { unsigned short size; unsigned short pad; struct i596_tbd *next; char *data;};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 */};struct i596_rfd { unsigned short stat; unsigned short cmd; struct i596_rfd *next; long rbd; unsigned short count; unsigned short size; char data[1532];};#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; volatile struct i596_iscp iscp; volatile struct i596_scb scb; struct i596_cmd set_add; char eth_addr[8]; struct i596_cmd set_conf; char i596_config[16]; struct i596_cmd tdr; unsigned long stat; int last_restart __attribute__((aligned(4))); struct i596_rfd *rx_tail; struct i596_cmd *cmd_tail; struct i596_cmd *cmd_head; int cmd_backlog; unsigned long last_cmd; struct net_device_stats stats;};char init_setup[] ={ 0x8E, /* length, prefetch on */ 0xC8, /* fifo to 8, monitor off */#ifdef CONFIG_VME 0xc0, /* don't save bad frames */#else 0x80, /* don't save bad frames */#endif 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 i596_open(struct device *dev);static int i596_start_xmit(struct sk_buff *skb, struct device *dev);static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs);static int i596_close(struct device *dev);static struct net_device_stats *i596_get_stats(struct device *dev);static void i596_add_cmd(struct device *dev, struct i596_cmd *cmd);static void print_eth(char *);static void set_multicast_list(struct device *dev);static int ticks_limit = 25;static int max_cmd_backlog = 16;static inline void CA(struct device *dev){#ifdef CONFIG_MVME16x_NET if (MACH_IS_MVME16x) { ((struct i596_reg *) dev->base_addr)->ca = 1; }#endif#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) { volatile u32 i = *(volatile u32 *) (dev->base_addr); }#endif#ifdef CONFIG_APRICOT_i596 if (MACH_IS_APRICOT) { outw(0, (short) (dev->base_addr) + 4); }#endif}static inline void MPU_PORT(struct device *dev, int c, volatile void *x){#ifdef CONFIG_MVME16x_NET if (MACH_IS_MVME16x) { struct i596_reg *p = (struct i596_reg *) (dev->base_addr); p->porthi = ((c) | (u32) (x)) & 0xffff; p->portlo = ((c) | (u32) (x)) >> 16; }#endif#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) { u32 v = (u32) (c) | (u32) (x); v = ((u32) (v) << 16) | ((u32) (v) >> 16); *(volatile u32 *) dev->base_addr = v; udelay(1); *(volatile u32 *) dev->base_addr = v; }#endif}#if defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)static void i596_error(int irq, void *dev_id, struct pt_regs *regs){ struct device *dev = dev_id; struct i596_cmd *cmd; struct i596_private *lp = (struct i596_private *) dev->priv; printk("i596_error: lp = 0x%08x\n", (u32) lp); printk("scp at %08x, .sysbus = %08x, .iscp = %08x\n", (u32) & lp->scp, (u32) lp->scp.sysbus, (u32) lp->scp.iscp); printk("iscp at %08x, .stat = %08x, .scb = %08x\n", (u32) & lp->iscp, (u32) lp->iscp.stat, (u32) lp->iscp.scb); printk("scb at %08x, .status = %04x, .command = %04x\n", (u32) & lp->scb, lp->scb.status, lp->scb.command); printk(" .cmd = %08x, .rfd = %08x\n", (u32) lp->scb.cmd, (u32) lp->scb.rfd); cmd = WSWAPcmd(lp->scb.cmd); while (cmd && (u32) cmd < 0x1000000) { printk("cmd at %08x, .status = %04x, .command = %04x, .next = %08x\n", (u32) cmd, cmd->status, cmd->command, (u32) cmd->next); cmd = WSWAPcmd(cmd->next); } while (1);}#endifstatic inline int init_rx_bufs(struct device *dev, int num){ struct i596_private *lp = (struct i596_private *) dev->priv; int i; struct i596_rfd *rfd; lp->scb.rfd = (struct i596_rfd *) I596_NULL; if (i596_debug > 1) printk("%s: init_rx_bufs %d.\n", dev->name, num); for (i = 0; i < num; i++) { if (!(rfd = (struct i596_rfd *) kmalloc(sizeof(struct i596_rfd), GFP_KERNEL))) break; rfd->stat = 0x0000; rfd->rbd = I596_NULL; rfd->count = 0; rfd->size = 1532; if (i == 0) { rfd->cmd = CMD_EOL; lp->rx_tail = rfd; } else rfd->cmd = 0x0000; rfd->next = lp->scb.rfd; lp->scb.rfd = WSWAPrfd(rfd); } if (i != 0) lp->rx_tail->next = lp->scb.rfd; return (i);}static inline void remove_rx_bufs(struct device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; struct i596_rfd *rfd = WSWAPrfd(lp->scb.rfd); lp->rx_tail->next = (struct i596_rfd *) I596_NULL; do { lp->scb.rfd = rfd->next; kfree(rfd); rfd = WSWAPrfd(lp->scb.rfd); } while (rfd != lp->rx_tail);}static inline void init_i596_mem(struct device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv;#if !defined(CONFIG_MVME16x_NET) && !defined(CONFIG_BVME6000_NET) short ioaddr = dev->base_addr;#endif int boguscnt = 100000; unsigned long flags;#if defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)#ifdef CONFIG_MVME16x_NET if (MACH_IS_MVME16x) { volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000; /* Disable all ints for now */ pcc2[0x28] = 1; pcc2[0x2a] = 0x40; pcc2[0x2b] = 0x40; /* Set snooping bits now! */ }#endif#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) { volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG; *ethirq = 1; }#endif MPU_PORT(dev, PORT_RESET, 0); udelay(100); /* Wait 100us - seems to help */ /* change the scp address */ MPU_PORT(dev, PORT_ALTSCP, &lp->scp);#else /* change the scp address */ outw(0, ioaddr); outw(0, ioaddr); outb(4, ioaddr + 0xf); outw(((((int) &lp->scp) & 0xffff) | 2), ioaddr); outw((((int) &lp->scp) >> 16) & 0xffff, ioaddr);#endif lp->last_cmd = jiffies;#ifdef CONFIG_MVME16x_NET if (MACH_IS_MVME16x) lp->scp.sysbus = 0x00000054;#endif#ifdef CONFIG_BVME6000_NET if (MACH_IS_BVME6000) lp->scp.sysbus = 0x0000004c;#endif#ifdef CONFIG_APRICOT_i596 if (MACH_IS_APRICOT) lp->scp.sysbus = 0x00440000;#endif lp->scp.iscp = WSWAPiscp(&(lp->iscp)); lp->iscp.scb = WSWAPscb(&(lp->scb));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -