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

📄 daynaport.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* mac_ns8390.c: A Macintosh 8390 based ethernet driver for linux. *//*	Derived from code:		Written 1993-94 by Donald Becker.	Copyright 1993 United States Government as represented by the	Director, National Security Agency.	This software may be used and distributed according to the terms	of the GNU Public License, incorporated herein by reference.	    TODO:	    The block output routines may be wrong for non Dayna	    cards	    Reading MAC addresses*/static const char *version =	"mac_ns8390.c:v0.01 7/5/97 Alan Cox (Alan.Cox@linux.org)\n";#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/nubus.h>#include <asm/io.h>#include <asm/system.h>#include <asm/hwtest.h>#include <linux/delay.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include "8390.h"int ns8390_probe1(struct device *dev, int word16, char *name, int id, int prom);static int ns8390_open(struct device *dev);static void ns8390_no_reset(struct device *dev);static int ns8390_close_card(struct device *dev);static void interlan_reset(struct device *dev);static void dayna_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,						int ring_page);static void dayna_block_input(struct device *dev, int count,						  struct sk_buff *skb, int ring_offset);static void dayna_block_output(struct device *dev, int count,						   const unsigned char *buf, const int start_page);static void sane_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,						int ring_page);static void sane_block_input(struct device *dev, int count,						  struct sk_buff *skb, int ring_offset);static void sane_block_output(struct device *dev, int count,						   const unsigned char *buf, const int start_page);static void slow_sane_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,						int ring_page);static void slow_sane_block_input(struct device *dev, int count,						  struct sk_buff *skb, int ring_offset);static void slow_sane_block_output(struct device *dev, int count,						   const unsigned char *buf, const int start_page);#define WD_START_PG	0x00	/* First page of TX buffer */#define WD03_STOP_PG	0x20	/* Last page +1 of RX ring */#define WD13_STOP_PG	0x40	/* Last page +1 of RX ring */#define DAYNA_MAC_BASE		0xf0007#define DAYNA_8390_BASE		0x80000 /* 3 */#define DAYNA_8390_MEM		0x00000#define DAYNA_MEMSIZE		0x04000	/* First word of each long ! */#define APPLE_8390_BASE		0xE0000#define APPLE_8390_MEM		0xD0000#define APPLE_MEMSIZE		8192    /* FIXME: need to dynamically check */#define KINETICS_8390_BASE	0x80003#define KINETICS_8390_MEM	0x00000#define KINETICS_MEMSIZE	8192    /* FIXME: need to dynamically check */static int test_8390(volatile char *ptr, int scale){	int regd;	int v;		if(hwreg_present(&ptr[0x00])==0)		return -EIO;	if(hwreg_present(&ptr[0x0D<<scale])==0)		return -EIO;	if(hwreg_present(&ptr[0x0D<<scale])==0)		return -EIO;	ptr[0x00]=E8390_NODMA+E8390_PAGE1+E8390_STOP;	regd=ptr[0x0D<<scale];	ptr[0x0D<<scale]=0xFF;	ptr[0x00]=E8390_NODMA+E8390_PAGE0;	v=ptr[0x0D<<scale];	if(ptr[0x0D<<scale]!=0)	{		ptr[0x0D<<scale]=regd;		return -ENODEV;	}/*	printk("NS8390 found at %p scaled %d\n", ptr,scale);*/	return 0;}/* *    Identify the species of NS8390 card/driver we need */#define NS8390_DAYNA		1#define NS8390_INTERLAN		2#define NS8390_KINETICS		3#define NS8390_APPLE		4#define NS8390_FARALLON		5#define NS8390_ASANTE		6int ns8390_ident(struct nubus_type *nb){	/* It appears anything with a software type of 0 is an apple	   compatible - even if the hardware matches others */	   	if(nb->DrSW==0x0001 || nb->DrSW==0x0109 || nb->DrSW==0x0000 || nb->DrSW==0x0100)		return NS8390_APPLE;		/* Dayna ex Kinetics board */	if(nb->DrHW==0x0103)		return NS8390_DAYNA;	/* Asante board */	if(nb->DrHW==0x0104)		return NS8390_ASANTE;	if(nb->DrHW==0x0100)		return NS8390_INTERLAN;	if(nb->DrHW==0x0106)		return NS8390_KINETICS;	if(nb->DrSW==0x010C)		return NS8390_FARALLON;	return -1;}/* *	Memory probe for 8390 cards */ int apple_8390_mem_probe(volatile unsigned short *p){	int i, j;	/*	 *	Algorithm.	 *	1.	Check each block size of memory doesn't fault	 *	2.	Write a value to it	 *	3.	Check all previous blocks are unaffected	 */		for(i=0;i<2;i++)	{		volatile unsigned short *m=p+4096*i;		/* Unwriteable - we have a fully decoded card and the		   RAM end located */		   		if(hwreg_present(m)==0)			return 8192*i;					*m=0xA5A0|i;				for(j=0;j<i;j++)		{			/* Partial decode and wrap ? */			if(p[4096*j]!=(0xA5A0|j))			{				/* This is the first misdecode, so it had				   one less page than we tried */				return 8192*i;			} 			j++; 		} 		/* Ok it still decodes.. move on 8K */ 	} 	/*  	 *	We don't look past 16K. That should cover most cards 	 *	and above 16K there isnt really any gain. 	 */ 	return 16384; } 		/* *    Probe for 8390 cards.   *    The ns8390_probe1() routine initializes the card and fills the *    station address field. On entry base_addr is set, irq is set *    (These come from the nubus probe code). dev->mem_start points *    at the memory ring, dev->mem_end gives the end of it. */int ns8390_probe(struct nubus_device_specifier *d, int slot, struct nubus_type *match){	struct device *dev;	volatile unsigned short *i;	volatile unsigned char *p;	int plen;	int id;	if(match->category!=NUBUS_CAT_NETWORK || match->type!=1)		return -ENODEV;			/* Ok so it is an ethernet network device */	if((id=ns8390_ident(match))==-1)	{		printk("Ethernet but type unknown %d\n",match->DrHW);		return -ENODEV;	}	dev = init_etherdev(0, 0);	if(dev==NULL)		return -ENOMEM;	/*	 *	Dayna specific init	 */	if(id==NS8390_DAYNA)	{		dev->base_addr=(int)(nubus_slot_addr(slot)+DAYNA_8390_BASE);		dev->mem_start=(int)(nubus_slot_addr(slot)+DAYNA_8390_MEM);		dev->mem_end=dev->mem_start+DAYNA_MEMSIZE; /* 8K it seems */			printk("daynaport: testing board: ");		printk("memory - ");				i=(void *)dev->mem_start;		memset((void *)i,0xAA, DAYNA_MEMSIZE);		while(i<(volatile unsigned short *)dev->mem_end)		{			if(*i!=0xAAAA)				goto membad;			*i=0x5555;			if(*i!=0x5555)				goto membad;			i+=2;	/* Skip a word */		}		printk("controller - ");			p=(void *)dev->base_addr;		plen=0;			while(plen<0x3FF00)		{			if(test_8390(p,0)==0)				break;			if(test_8390(p,1)==0)				break;			if(test_8390(p,2)==0)				break;			if(test_8390(p,3)==0)				break;			plen++;			p++;		}		if(plen==0x3FF00)			goto membad;		printk("OK\n");		dev->irq=slot;		if(ns8390_probe1(dev, 0, "dayna", id, -1)==0)		return 0;	}	/* Apple, Farallon, Asante */	if(id==NS8390_APPLE|| id==NS8390_FARALLON || id==NS8390_ASANTE)	{		int memsize;				dev->base_addr=(int)(nubus_slot_addr(slot)+APPLE_8390_BASE);		dev->mem_start=(int)(nubus_slot_addr(slot)+APPLE_8390_MEM);				memsize = apple_8390_mem_probe((void *)dev->mem_start);				dev->mem_end=dev->mem_start+memsize;		dev->irq=slot;		printk("apple/clone: testing board: ");		printk("%dK memory - ", memsize>>10);				i=(void *)dev->mem_start;		memset((void *)i,0xAA, memsize);		while(i<(volatile unsigned short *)dev->mem_end)		{			if(*i!=0xAAAA)				goto membad;			*i=0x5555;			if(*i!=0x5555)				goto membad;			i+=2;	/* Skip a word */		}		printk("OK\n");		if(id==NS8390_FARALLON)		{			if(ns8390_probe1(dev, 1, "farallon", id, -1)==0)				return 0;		}		else		{			if(ns8390_probe1(dev, 1, "apple/clone", id, -1)==0)			    return 0;		}	}	/* Interlan */	if(id==NS8390_INTERLAN)	{		/* As apple and asante */		dev->base_addr=(int)(nubus_slot_addr(slot)+APPLE_8390_BASE);		dev->mem_start=(int)(nubus_slot_addr(slot)+APPLE_8390_MEM);		dev->mem_end=dev->mem_start+APPLE_MEMSIZE; /* 8K it seems */		dev->irq=slot;		if(ns8390_probe1(dev, 1, "interlan", id, -1)==0)			return 0;	}	/* Kinetics */	if(id==NS8390_KINETICS)	{		dev->base_addr=(int)(nubus_slot_addr(slot)+KINETICS_8390_BASE);		dev->mem_start=(int)(nubus_slot_addr(slot)+KINETICS_8390_MEM);		dev->mem_end=dev->mem_start+KINETICS_MEMSIZE; /* 8K it seems */		dev->irq=slot;		if(ns8390_probe1(dev, 0, "kinetics", id, -1)==0)			return 0;	}	kfree(dev);	return -ENODEV;membad:	printk("failed.\n");	kfree(dev);	return -ENODEV;}int ns8390_probe1(struct device *dev, int word16, char *model_name, int type, int promoff){	static unsigned version_printed = 0;	static u32 fwrd4_offsets[16]={		0,      4,      8,      12,		16,     20,     24,     28,		32,     36,     40,     44,		48,     52,     56,     60	};	static u32 back4_offsets[16]={		60,     56,     52,     48,		44,     40,     36,     32,		28,     24,     20,     16,		12,     8,      4,      0	};	unsigned char *prom=((unsigned char *)nubus_slot_addr(dev->irq))+promoff;	if (ei_debug  &&  version_printed++ == 0)		printk(version);		/* Snarf the interrupt now.  There's no point in waiting since we cannot	   share a slot! and the board will usually be enabled. */	if (nubus_request_irq(dev->irq, dev, ei_interrupt)) 	{		printk (" unable to get nubus IRQ %d.\n", dev->irq);		return EAGAIN;	}		/* Allocate dev->priv and fill in 8390 specific dev fields. */	if (ethdev_init(dev)) 	{			printk (" unable to get memory for dev->priv.\n");		nubus_free_irq(dev->irq);

⌨️ 快捷键说明

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