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

📄 ne2k-pci.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 2 页
字号:
	}#if defined(LOAD_8390_BY_KERNELD)	/* We are now certain the 8390 module is required. */	if (request_module("8390")) {		printk("ne2k-pci: Failed to load the 8390 core module.\n");		return 0;	}	if ((Lethdev_init = (void*)get_module_symbol(0, "ethdev_init")) == 0 ||		(LNS8390_init = (void*)get_module_symbol(0, "NS8390_init")) == 0 ||		(Lei_open = (void*)get_module_symbol(0, "ei_open")) == 0 ||		(Lei_close = (void*)get_module_symbol(0, "ei_close")) == 0 ||		(Lei_interrupt = (void*)get_module_symbol(0, "ei_interrupt")) == 0 ) {		printk("ne2k-pci: Failed to resolve an 8390 symbol.\n");		release_module("8390", 0);		return 0;	}#endif	/* Read the 16 bytes of station address PROM.	   We must first initialize registers, similar to NS8390_init(eifdev, 0).	   We can't reliably read the SAPROM address without this.	   (I learned the hard way!). */	{		struct {unsigned char value, offset; } program_seq[] = {			{E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/			{0x49,	EN0_DCFG},	/* Set word-wide access. */			{0x00,	EN0_RCNTLO},	/* Clear the count regs. */			{0x00,	EN0_RCNTHI},			{0x00,	EN0_IMR},	/* Mask completion irq. */			{0xFF,	EN0_ISR},			{E8390_RXOFF, EN0_RXCR},	/* 0x20  Set to monitor */			{E8390_TXOFF, EN0_TXCR},	/* 0x02  and loopback mode. */			{32,	EN0_RCNTLO},			{0x00,	EN0_RCNTHI},			{0x00,	EN0_RSARLO},	/* DMA starting at 0x0000. */			{0x00,	EN0_RSARHI},			{E8390_RREAD+E8390_START, E8390_CMD},		};		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)			outb(program_seq[i].value, ioaddr + program_seq[i].offset);	}#ifdef notdef	/* Some broken PCI cards don't respect the byte-wide	   request in program_seq above, and hence don't have doubled up values.	*/	for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {		SA_prom[i] = inb(ioaddr + NE_DATAPORT);		SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);		if (SA_prom[i] != SA_prom[i+1])			sa_prom_doubled = 0;	}	if (sa_prom_doubled)		for (i = 0; i < 16; i++)			SA_prom[i] = SA_prom[i+i];#else	for(i = 0; i < 32 /*sizeof(SA_prom)*/; i++)		SA_prom[i] = inb(ioaddr + NE_DATAPORT);#endif	/* We always set the 8390 registers for word mode. */	outb(0x49, ioaddr + EN0_DCFG);	start_page = NESM_START_PG;	stop_page = NESM_STOP_PG;	/* Set up the rest of the parameters. */	name = "PCI NE2000";	dev->irq = irq;	dev->base_addr = ioaddr;	/* Allocate dev->priv and fill in 8390 specific dev fields. */	if (Lethdev_init(dev)) {		printk ("%s: unable to get memory for dev->priv.\n", dev->name);		return 0;	}	request_region(ioaddr, NE_IO_EXTENT, dev->name);	printk("%s: %s found at %#x, IRQ %d, ",		   dev->name, name, ioaddr, dev->irq);	for(i = 0; i < 6; i++) {		printk("%2.2X%s", SA_prom[i], i == 5 ? ".\n": ":");		dev->dev_addr[i] = SA_prom[i];	}	ei_status.name = name;	ei_status.tx_start_page = start_page;	ei_status.stop_page = stop_page;	ei_status.word16 = 1;	ei_status.rx_start_page = start_page + TX_PAGES;#ifdef PACKETBUF_MEMSIZE	/* Allow the packet buffer size to be overridden by know-it-alls. */	ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;#endif	ei_status.reset_8390 = &ne_reset_8390;	ei_status.block_input = &ne_block_input;	ei_status.block_output = &ne_block_output;	ei_status.get_8390_hdr = &ne_get_8390_hdr;	dev->open = &ne_open;	dev->stop = &ne_close;	LNS8390_init(dev, 0);	return dev;}static intne_open(struct device *dev){	if (request_irq(dev->irq, Lei_interrupt, SA_SHIRQ, dev->name, dev))		return -EAGAIN;	Lei_open(dev);	MOD_INC_USE_COUNT;	return 0;}static intne_close(struct device *dev){	Lei_close(dev);	free_irq(dev->irq, dev);	MOD_DEC_USE_COUNT;	return 0;}/* Hard reset the card.  This used to pause for the same period that a   8390 reset command required, but that shouldn't be necessary. */static voidne_reset_8390(struct device *dev){	unsigned long reset_start_time = jiffies;	if (debug > 1) printk("%s: Resetting the 8390 t=%ld...",						  dev->name, jiffies);	outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);	ei_status.txing = 0;	ei_status.dmaing = 0;	/* This check _should_not_ be necessary, omit eventually. */	while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)		if (jiffies - reset_start_time > 2) {			printk("%s: ne_reset_8390() did not complete.\n", dev->name);			break;		}	outb(ENISR_RESET, NE_BASE + EN0_ISR);	/* Ack intr. */}/* Grab the 8390 specific header. Similar to the block_input routine, but   we don't need to be concerned with ring wrap as the header will be at   the start of a page, so we optimize accordingly. */static voidne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page){	int nic_base = dev->base_addr;	/* This *shouldn't* happen. If it does, it's the last thing you'll see */	if (ei_status.dmaing) {		printk("%s: DMAing conflict in ne_get_8390_hdr "			   "[DMAstat:%d][irqlock:%d][intr:%d].\n",			   dev->name, ei_status.dmaing, ei_status.irqlock,			   dev->interrupt);		return;	}	ei_status.dmaing |= 0x01;	outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);	outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);	outb(0, nic_base + EN0_RCNTHI);	outb(0, nic_base + EN0_RSARLO);		/* On page boundary */	outb(ring_page, nic_base + EN0_RSARHI);	outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);#if defined(USE_LONGIO)	*(u32*)hdr = inl(NE_BASE + NE_DATAPORT);#else	insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);#endif	outb(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */	ei_status.dmaing &= ~0x01;}/* Block input and output, similar to the Crynwr packet driver.  If you   are porting to a new ethercard, look at the packet driver source for hints.   The NEx000 doesn't share the on-board packet memory -- you have to put   the packet out through the "remote DMA" dataport using outb. */static voidne_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset){	int nic_base = dev->base_addr;	char *buf = skb->data;	/* This *shouldn't* happen. If it does, it's the last thing you'll see */	if (ei_status.dmaing) {		printk("%s: DMAing conflict in ne_block_input "			   "[DMAstat:%d][irqlock:%d][intr:%d].\n",			   dev->name, ei_status.dmaing, ei_status.irqlock,			   dev->interrupt);		return;	}	ei_status.dmaing |= 0x01;	outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);	outb(count & 0xff, nic_base + EN0_RCNTLO);	outb(count >> 8, nic_base + EN0_RCNTHI);	outb(ring_offset & 0xff, nic_base + EN0_RSARLO);	outb(ring_offset >> 8, nic_base + EN0_RSARHI);	outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);#if defined(USE_LONGIO)	insl(NE_BASE + NE_DATAPORT, buf, count>>2);	if (count & 3) {		buf += count & ~3;		if (count & 2)			*((u16*)buf)++ = inw(NE_BASE + NE_DATAPORT);		if (count & 1)			*buf = inb(NE_BASE + NE_DATAPORT);	}#else	insw(NE_BASE + NE_DATAPORT,buf,count>>1);	if (count & 0x01) {		buf[count-1] = inb(NE_BASE + NE_DATAPORT);	}#endif	outb(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */	ei_status.dmaing &= ~0x01;}static voidne_block_output(struct device *dev, int count,		const unsigned char *buf, const int start_page){	int nic_base = NE_BASE;	unsigned long dma_start;	/* On little-endian it's always safe to round the count up for	   word writes. */	if (count & 0x01)		count++;	/* This *shouldn't* happen. If it does, it's the last thing you'll see */	if (ei_status.dmaing) {		printk("%s: DMAing conflict in ne_block_output."			   "[DMAstat:%d][irqlock:%d][intr:%d]\n",			   dev->name, ei_status.dmaing, ei_status.irqlock,			   dev->interrupt);		return;	}	ei_status.dmaing |= 0x01;	/* We should already be in page 0, but to be safe... */	outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);#ifdef NE8390_RW_BUGFIX	/* Handle the read-before-write bug the same way as the	   Crynwr packet driver -- the NatSemi method doesn't work.	   Actually this doesn't always work either, but if you have	   problems with your NEx000 this is better than nothing! */	outb(0x42, nic_base + EN0_RCNTLO);	outb(0x00, nic_base + EN0_RCNTHI);	outb(0x42, nic_base + EN0_RSARLO);	outb(0x00, nic_base + EN0_RSARHI);	outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);#endif	outb(ENISR_RDC, nic_base + EN0_ISR);   /* Now the normal output. */	outb(count & 0xff, nic_base + EN0_RCNTLO);	outb(count >> 8,   nic_base + EN0_RCNTHI);	outb(0x00, nic_base + EN0_RSARLO);	outb(start_page, nic_base + EN0_RSARHI);	outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);#if defined(USE_LONGIO)	outsl(NE_BASE + NE_DATAPORT, buf, count>>2);	if (count & 3) {		buf += count & ~3;		if (count & 2)			outw(*((u16*)buf)++, NE_BASE + NE_DATAPORT);	}#else	outsw(NE_BASE + NE_DATAPORT, buf, count>>1);#endif	dma_start = jiffies;	while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0)		if (jiffies - dma_start > 2) { 			/* Avoid clock roll-over. */			printk("%s: timeout waiting for Tx RDC.\n", dev->name);			ne_reset_8390(dev);			LNS8390_init(dev,1);			break;		}	outb(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */	ei_status.dmaing &= ~0x01;	return;}/* * Local variables: *  compile-command: "gcc -DMODVERSIONS  -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/ -c ne2k-pci.c" *  alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/ -c ne2k-pci.c" *  c-indent-level: 4 *  c-basic-offset: 4 *  tab-width: 4 *  version-control: t *  kept-new-versions: 5 * End: */

⌨️ 快捷键说明

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