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

📄 ether1.c

📁 arm平台上的uclinux系统全部源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * linux/arch/arm/drivers/net/ether1.c * * Acorn ether1 driver (82586 chip) * * (c) 1996 Russell King *//* * We basically keep two queues in the cards memory - one for transmit * and one for receive.  Each has a head and a tail.  The head is where * we/the chip adds packets to be transmitted/received, and the tail * is where the transmitter has got to/where the receiver will stop. * Both of these queues are circular, and since the chip is running * all the time, we have to be careful when we modify the pointers etc * so that the buffer memory is valid all the time. *//* * Change log: * 1.00	RMK			Released * 1.01	RMK	19/03/96	Transfers the last odd byte onto/off of the card now. * 1.02	RMK	25/05/97	Added code to restart RU if it goes not ready * 1.03	RMK	14/09/97	Cleaned up the handling of a reset during the TX interrupt. *				Should prevent lockup. * 1.04 RMK	17/09/97	Added more info when initialsation of chip goes wrong. *				TDR now only reports failure when chip reports non-zero *				TDR time-distance. */#include <linux/module.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/malloc.h>#include <linux/string.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <linux/errno.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <asm/ecard.h>#define __ETHER1_C#include "ether1.h"static unsigned int net_debug = NET_DEBUG;#define FUNC_PROLOGUE \	struct ether1_priv *priv = (struct ether1_priv *)dev->priv#define BUFFER_SIZE	0x10000#define TX_AREA_START	0x00100#define TX_AREA_END	0x05000#define RX_AREA_START	0x05000#define RX_AREA_END	0x0fc00#define tx_done(dev) 0/* ------------------------------------------------------------------------- */static char *version = "ether1 ethernet driver (c) 1995 Russell King v1.04\n";#define BUS_16 16#define BUS_8  8static const card_ids ether1_cids[] = {	{ MANU_ACORN, PROD_ACORN_ETHER1 },	{ 0xffff, 0xffff }};/* ------------------------------------------------------------------------- */#define DISABLEIRQS 1#define NORMALIRQS  0#define ether1_inw(dev, addr, type, offset, svflgs) ether1_inw_p(dev, addr + (int)(&((type *)0)->offset), svflgs)#define ether1_outw(dev, val, addr, type, offset, svflgs) ether1_outw_p(dev, val, addr + (int)(&((type *)0)->offset), svflgs)static inline unsigned shortether1_inw_p(const struct device *dev, int addr, const int svflgs){    unsigned long flags;    unsigned short ret;    if (svflgs) {	save_flags_cli(flags);    }    outb(addr >> 12, REG_PAGE);    ret = inw(ETHER1_RAM + ((addr & 4095) >> 1));    if (svflgs)	restore_flags(flags);    return ret;}static inline voidether1_outw_p(const struct device *dev, unsigned short val, int addr, const int svflgs){    unsigned long flags;    if (svflgs) {	save_flags_cli(flags);    }    outb(addr >> 12, REG_PAGE);    outw(val, ETHER1_RAM + ((addr & 4095) >> 1));    if (svflgs)	restore_flags(flags);}static inline void *ether1_inswb(unsigned int addr, void *data, unsigned int len){    int used;    addr = IO_BASE + (addr << 2);    __asm__ __volatile__(	"subs	%3, %3, #2	bmi	2f1:	ldr	%0, [%1], #4	strb	%0, [%2], #1	mov	%0, %0, lsr #8	strb	%0, [%2], #1	subs	%3, %3, #2	bmi	2f	ldr	%0, [%1], #4	strb	%0, [%2], #1	mov	%0, %0, lsr #8	strb	%0, [%2], #1	subs	%3, %3, #2	bmi	2f	ldr	%0, [%1], #4	strb	%0, [%2], #1	mov	%0, %0, lsr #8	strb	%0, [%2], #1	subs	%3, %3, #2	bmi	2f	ldr	%0, [%1], #4	strb	%0, [%2], #1	mov	%0, %0, lsr #8	strb	%0, [%2], #1	subs	%3, %3, #2	bpl	1b2:	adds	%3, %3, #1	ldreqb	%0, [%1]	streqb	%0, [%2]"    : "=&r" (used), "=&r" (addr), "=&r" (data), "=&r" (len)    :                "1"  (addr), "2"   (data), "3"   (len));    return data;}static inline void *ether1_outswb(unsigned int addr, void *data, unsigned int len){    int used;    addr = IO_BASE + (addr << 2);    __asm__ __volatile__(	"subs	%3, %3, #2	bmi	2f1:	ldr	%0, [%2], #2	mov	%0, %0, lsl #16	orr	%0, %0, %0, lsr #16	str	%0, [%1], #4	subs	%3, %3, #2	bmi	2f	ldr	%0, [%2], #2	mov	%0, %0, lsl #16	orr	%0, %0, %0, lsr #16	str	%0, [%1], #4	subs	%3, %3, #2	bmi	2f	ldr	%0, [%2], #2	mov	%0, %0, lsl #16	orr	%0, %0, %0, lsr #16	str	%0, [%1], #4	subs	%3, %3, #2	bmi	2f	ldr	%0, [%2], #2	mov	%0, %0, lsl #16	orr	%0, %0, %0, lsr #16	str	%0, [%1], #4	subs	%3, %3, #2	bpl	1b2:	adds	%3, %3, #1	ldreqb	%0, [%2]	streqb	%0, [%1]"    : "=&r" (used), "=&r" (addr), "=&r" (data), "=&r" (len)    :                "1"  (addr), "2"   (data), "3"   (len));    return data;}static voidether1_writebuffer(struct device *dev, void *data, unsigned int start, unsigned int length){    unsigned int page, thislen, offset;    offset = start & 4095;    for (page = start >> 12; length; page++) {	outb(page, REG_PAGE);	if (offset + length > 4096) {	    length -= 4096 - offset;	    thislen = 4096 - offset;	} else {	    thislen = length;	    length = 0;	}	data = ether1_outswb(ETHER1_RAM + (offset >> 1), data, thislen);	offset = 0;    }}static voidether1_readbuffer(struct device *dev, void *data, unsigned int start, unsigned int length){    unsigned int page, thislen, offset;    offset = start & 4095;    for (page = start >> 12; length; page++) {	outb(page, REG_PAGE);	if (offset + length > 4096) {	    length -= 4096 - offset;	    thislen = 4096 - offset;	} else {	    thislen = length;	    length = 0;	}	data = ether1_inswb(ETHER1_RAM + (offset >> 1), data, thislen);	offset = 0;    }}static intether1_ramtest(struct device *dev, unsigned char byte){    unsigned char *buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);    int i, ret = BUFFER_SIZE;    int max_errors = 15;    int bad = -1;    int bad_start = 0;    if (!buffer)	return 1;    memset(buffer, byte, BUFFER_SIZE);    ether1_writebuffer(dev, buffer, 0, BUFFER_SIZE);    memset(buffer, byte ^ 0xff, BUFFER_SIZE);    ether1_readbuffer(dev, buffer, 0, BUFFER_SIZE);    for (i = 0; i < BUFFER_SIZE; i++) {	if (buffer[i] != byte) {	    if (max_errors >= 0 && bad != buffer[i]) {		if (bad != -1)		    printk("\n");		printk(KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",			dev->name, buffer[i], byte, i);		ret = -ENODEV;		max_errors --;		bad = buffer[i];		bad_start = i;	    }	} else {	    if (bad != -1) {	    	if (bad_start == i - 1)		    printk("\n");		else		    printk(" - 0x%04X\n", i - 1);		bad = -1;	    }	}    }    if (bad != -1)	printk(" - 0x%04X\n", BUFFER_SIZE);    kfree(buffer);    return ret;}static intether1_reset(struct device *dev){    outb(CTRL_RST|CTRL_ACK, REG_CONTROL);    return BUS_16;}static intether1_init_2(struct device *dev){    int i;    dev->mem_start = 0;    i = ether1_ramtest(dev, 0x5a);    if (i > 0)	i = ether1_ramtest(dev, 0x1e);    if (i <= 0)    	return -ENODEV;    dev->mem_end = i;    return 0;}/* * These are the structures that are loaded into the ether RAM card to * initialise the 82586 *//* at 0x0100 */#define NOP_ADDR	(TX_AREA_START)#define NOP_SIZE	(0x06)static nop_t  init_nop  = {	{ 0, CMD_NOP },	NOP_ADDR};/* at 0x003a */#define TDR_ADDR	(0x003a)#define TDR_SIZE	(0x08)static tdr_t  init_tdr	= {	{ 0, CMD_TDR | CMD_INTR },	NOP_ADDR, 0};/* at 0x002e */#define MC_ADDR		(0x002e)#define MC_SIZE		(0x0c)static mc_t   init_mc   = {	{ 0, CMD_SETMULTICAST },	TDR_ADDR, 0, { { 0, } }};/* at 0x0022 */#define SA_ADDR		(0x0022)#define SA_SIZE		(0x0c)static sa_t   init_sa   = {	{ 0, CMD_SETADDRESS },	MC_ADDR, { 0, }};/* at 0x0010 */#define CFG_ADDR	(0x0010)#define CFG_SIZE	(0x12)static cfg_t  init_cfg  = {	{ 0, CMD_CONFIG },	SA_ADDR,	8,	8,	CFG8_SRDY,	CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),	0,	0x60,	0,	CFG13_RETRY(15) | CFG13_SLOTH(2),	0,};/* at 0x0000 */#define SCB_ADDR	(0x0000)#define SCB_SIZE	(0x10)static scb_t  init_scb  = {	0,	SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,	CFG_ADDR,	RX_AREA_START,	0,	0,	0,	0};/* at 0xffee */#define ISCP_ADDR	(0xffee)#define ISCP_SIZE	(0x08)static iscp_t init_iscp = {	1,	SCB_ADDR,	0x0000,	0x0000};/* at 0xfff6 */#define SCP_ADDR	(0xfff6)#define SCP_SIZE	(0x0a)static scp_t  init_scp  = {	SCP_SY_16BBUS,	{ 0, 0 },	ISCP_ADDR,	0};#define RFD_SIZE	(0x16)#define RBD_SIZE	(0x0a)#define TX_SIZE		(0x08)#define TBD_SIZE	(0x08)static voidether1_setup_rx_buffer(struct device *dev){	struct ether1_priv *priv = (struct ether1_priv *)dev->priv;	unsigned int addr, next, next2;	rfd_t rfd;	rbd_t rbd;	memset(&rfd, 0, sizeof(rfd));	memset(&rbd, 0, sizeof(rbd));	rbd.rbd_len = ETH_FRAME_LEN + 8;	/*	 * setup circularly linked list of { rfd, rbd, buffer }, with	 * all rfds circularly linked, rbds circularly linked.	 * First rfd is linked to scp, first rbd is linked to first	 * rfd.  Last rbd has a suspend command.	 */	addr = RX_AREA_START;	do {		next  = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;		next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;		if (next2 >= RX_AREA_END) {			next = RX_AREA_START;			rfd.hdr.command = RFD_CMDEL | RFD_CMDSUSPEND;			priv->rx_tail = addr;		} else			rfd.hdr.command = 0;		if (addr == RX_AREA_START)			rfd.rfd_rbdoffset = RX_AREA_START + RFD_SIZE;		else			rfd.rfd_rbdoffset = 0;		rfd.rfd_link = next;		rbd.rbd_link = next + RFD_SIZE;		rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;		ether1_writebuffer(dev, &rfd, addr, RFD_SIZE);		ether1_writebuffer(dev, &rbd, addr + RFD_SIZE, RBD_SIZE);		addr = next;	} while (next2 < RX_AREA_END);}static intether1_init_for_open(struct device *dev){    FUNC_PROLOGUE;    int i, status;    int failures = 0;    outb(CTRL_RST|CTRL_ACK, REG_CONTROL);    for (i = 0; i < 6; i++)	init_sa.sa_addr[i] = dev->dev_addr[i];    /* load data structures into ether1 RAM */    ether1_writebuffer(dev, &init_scp,  SCP_ADDR,  SCP_SIZE);    ether1_writebuffer(dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);    ether1_writebuffer(dev, &init_scb,  SCB_ADDR,  SCB_SIZE);    ether1_writebuffer(dev, &init_cfg,  CFG_ADDR,  CFG_SIZE);    ether1_writebuffer(dev, &init_sa,   SA_ADDR,   SA_SIZE);    ether1_writebuffer(dev, &init_mc,   MC_ADDR,   MC_SIZE);    ether1_writebuffer(dev, &init_tdr,  TDR_ADDR,  TDR_SIZE);    ether1_writebuffer(dev, &init_nop,  NOP_ADDR,  NOP_SIZE);    if (ether1_inw(dev, CFG_ADDR, cfg_t, hdr.command, NORMALIRQS) != CMD_CONFIG) {	printk(KERN_ERR "%s: detected either RAM fault or compiler bug\n",		dev->name);	return 1;    }	ether1_setup_rx_buffer(dev);    priv->tx_link = NOP_ADDR;    priv->tx_head = NOP_ADDR + NOP_SIZE;    priv->tx_tail = TDR_ADDR;    priv->rx_head = RX_AREA_START;    /* release reset & give 586 a prod */    priv->resetting = 1;    priv->initialising = 1;    outb(CTRL_RST, REG_CONTROL);    outb(0, REG_CONTROL);    outb(CTRL_CA, REG_CONTROL);    /* 586 should now unset iscp.busy */    i = jiffies + HZ/2;    while (ether1_inw(dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {	if (jiffies > i) {	    printk(KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);	    return 1;	}    }    /* check status of commands that we issued */    i += HZ/10;    while (((status = ether1_inw(dev, CFG_ADDR, cfg_t, hdr.status, DISABLEIRQS))		& STAT_COMPLETE) == 0) {	if (jiffies > i)	    break;    }    if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {	printk(KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);	printk(KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,		ether1_inw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));	failures += 1;    }    i += HZ/10;    while (((status = ether1_inw(dev, SA_ADDR, sa_t, hdr.status, DISABLEIRQS))		& STAT_COMPLETE) == 0) {	if (jiffies > i)	    break;    }    if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {	printk(KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);	printk(KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,		ether1_inw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));	failures += 1;    }    i += HZ/10;    while (((status = ether1_inw(dev, MC_ADDR, mc_t, hdr.status, DISABLEIRQS))		& STAT_COMPLETE) == 0) {	if (jiffies > i)	    break;    }    if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {	printk(KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);	printk(KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,		ether1_inw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));	failures += 1;    }    i += HZ;    while (((status = ether1_inw(dev, TDR_ADDR, tdr_t, hdr.status, DISABLEIRQS))		& STAT_COMPLETE) == 0) {	if (jiffies > i)	    break;    }    if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {	printk(KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);	printk(KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,		ether1_inw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),		ether1_inw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));    } else {	status = ether1_inw(dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);	if (status & TDR_XCVRPROB)	    printk(KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);	else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {#ifdef FANCY	    printk(KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,		    status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,		    (status & TDR_TIME) % 10);#else

⌨️ 快捷键说明

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