?? ne2k-pci.c
字號:
/* ne2k-pci.c: A NE2000 clone on PCI bus driver for Linux. */
/*
A Linux device driver for PCI NE2000 clones.
Authorship and other copyrights:
1992-1998 by Donald Becker, NE2000 core and various modifications.
1995-1998 by Paul Gortmaker, core modifications and PCI support.
Copyright 1993 assigned to the 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.
The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
Center of Excellence in Space Data and Information Sciences
Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
People are making PCI ne2000 clones! Oh the horror, the horror...
Issues remaining:
No full-duplex support.
*/
/* Our copyright info must remain in the binary. */
static const char *version =
"ne2k-pci.c:vpre-1.00e 5/27/99 D. Becker/P. Gortmaker http://cesdis.gsfc.nasa.gov/linux/drivers/ne2k-pci.html\n";
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include "8390.h"
#if defined(__powerpc__)
#define inl_le(addr) le32_to_cpu(inl(addr))
#define inw_le(addr) le16_to_cpu(inw(addr))
#define insl insl_ns
#define outsl outsl_ns
#endif
/* Set statically or when loading the driver module. */
static int debug = 1;
/* Some defines that people can play with if so inclined. */
/* Use 32 bit data-movement operations instead of 16 bit. */
#define USE_LONGIO
/* Do we implement the read before write bugfix ? */
/* #define NE_RW_BUGFIX */
/* Do we have a non std. amount of memory? (in units of 256 byte pages) */
/* #define PACKETBUF_MEMSIZE 0x40 */
#define ne2k_flags reg0 /* Rename an existing field to store flags! */
/* Only the low 8 bits are usable for non-init-time flags! */
enum {
HOLTEK_FDX=1, /* Full duplex -> set 0x80 at offset 0x20. */
ONLY_16BIT_IO=2, ONLY_32BIT_IO=4, /* Chip can do only 16/32-bit xfers. */
STOP_PG_0x60=0x100,
};
/* This will eventually be converted to the standard PCI probe table. */
static struct {
unsigned short vendor, dev_id;
char *name;
int flags;
}
pci_clone_list[] __initdata = {
{0x10ec, 0x8029, "RealTek RTL-8029", 0},
{0x1050, 0x0940, "Winbond 89C940", 0},
{0x11f6, 0x1401, "Compex RL2000", 0},
{0x8e2e, 0x3000, "KTI ET32P2", 0},
{0x4a14, 0x5000, "NetVin NV5000SC", 0},
{0x1106, 0x0926, "Via 86C926", ONLY_16BIT_IO},
{0x10bd, 0x0e34, "SureCom NE34", 0},
{0x1050, 0x5a5a, "Winbond", 0},
{0x12c3, 0x0058, "Holtek HT80232", ONLY_16BIT_IO | HOLTEK_FDX},
{0x12c3, 0x5598, "Holtek HT80229",
ONLY_32BIT_IO | HOLTEK_FDX | STOP_PG_0x60 },
{0,}
};
/* ---- No user-serviceable parts below ---- */
#define NE_BASE (dev->base_addr)
#define NE_CMD 0x00
#define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
#define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
#define NE_IO_EXTENT 0x20
#define NESM_START_PG 0x40 /* First page of TX buffer */
#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
int ne2k_pci_probe(struct device *dev);
static struct device *ne2k_pci_probe1(struct device *dev, long ioaddr, int irq,
int chip_idx);
static int ne2k_pci_open(struct device *dev);
static int ne2k_pci_close(struct device *dev);
static void ne2k_pci_reset_8390(struct device *dev);
static void ne2k_pci_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
int ring_page);
static void ne2k_pci_block_input(struct device *dev, int count,
struct sk_buff *skb, int ring_offset);
static void ne2k_pci_block_output(struct device *dev, const int count,
const unsigned char *buf, const int start_page);
/* No room in the standard 8390 structure for extra info we need. */
struct ne2k_pci_card {
struct ne2k_pci_card *next;
struct device *dev;
struct pci_dev *pci_dev;
};
/* A list of all installed devices, for removing the driver module. */
static struct ne2k_pci_card *ne2k_card_list = NULL;
#ifdef MODULE
int
init_module(void)
{
/* We must emit version information. */
if (debug)
printk(KERN_INFO "%s", version);
if (ne2k_pci_probe(0)) {
printk(KERN_NOTICE "ne2k-pci.c: No useable cards found, driver NOT installed.\n");
return -ENODEV;
}
lock_8390_module();
return 0;
}
void
cleanup_module(void)
{
struct device *dev;
struct ne2k_pci_card *this_card;
/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
while (ne2k_card_list) {
dev = ne2k_card_list->dev;
unregister_netdev(dev);
release_region(dev->base_addr, NE_IO_EXTENT);
kfree(dev);
this_card = ne2k_card_list;
ne2k_card_list = ne2k_card_list->next;
kfree(this_card);
}
unlock_8390_module();
}
#endif /* MODULE */
/*
NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet
buffer memory space. By-the-spec NE2000 clones have 0x57,0x57 in bytes
0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be
detected by their SA prefix.
Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
mode results in doubled values, which can be detected and compensated for.
The probe is also responsible for initializing the card and filling
in the 'dev' and 'ei_status' structures.
*/
#ifdef HAVE_DEVLIST
struct netdev_entry netcard_drv =
{"ne2k_pci", ne2k_pci_probe1, NE_IO_EXTENT, 0};
#endif
__initfunc (int ne2k_pci_probe(struct device *dev))
{
struct pci_dev *pdev = NULL;
int cards_found = 0;
int i;
if ( ! pci_present())
return -ENODEV;
while ((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev)) != NULL) {
int pci_irq_line;
u16 pci_command, new_command;
unsigned long pci_ioaddr;
/* Note: some vendor IDs (RealTek) have non-NE2k cards as well. */
for (i = 0; pci_clone_list[i].vendor != 0; i++)
if (pci_clone_list[i].vendor == pdev->vendor
&& pci_clone_list[i].dev_id == pdev->device)
break;
if (pci_clone_list[i].vendor == 0)
continue;
pci_ioaddr = pdev->base_address[0] & PCI_BASE_ADDRESS_IO_MASK;
pci_irq_line = pdev->irq;
pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
/* Avoid already found cards from previous calls */
if (check_region(pci_ioaddr, NE_IO_EXTENT))
continue;
#ifndef MODULE
{
static unsigned version_printed = 0;
if (version_printed++ == 0)
printk(KERN_INFO "%s", version);
}
#endif
/* Activate the card: fix for brain-damaged Win98 BIOSes. */
new_command = pci_command | PCI_COMMAND_IO;
if (pci_command != new_command) {
printk(KERN_INFO " The PCI BIOS has not enabled this"
" NE2k clone! Updating PCI command %4.4x->%4.4x.\n",
pci_command, new_command);
pci_write_config_word(pdev, PCI_COMMAND, new_command);
}
#ifndef __sparc__
if (pci_irq_line <= 0 || pci_irq_line >= NR_IRQS)
printk(KERN_WARNING " WARNING: The PCI BIOS assigned this PCI NE2k"
" card to IRQ %d, which is unlikely to work!.\n"
KERN_WARNING " You should use the PCI BIOS setup to assign"
" a valid IRQ line.\n", pci_irq_line);
#endif
printk("ne2k-pci.c: PCI NE2000 clone '%s' at I/O %#lx, IRQ %d.\n",
pci_clone_list[i].name, pci_ioaddr, pci_irq_line);
dev = ne2k_pci_probe1(dev, pci_ioaddr, pci_irq_line, i);
if (dev == 0) {
/* Should not happen. */
printk(KERN_ERR "ne2k-pci: Probe of PCI card at %#lx failed.\n",
pci_ioaddr);
continue;
} else {
struct ne2k_pci_card *ne2k_card =
kmalloc(sizeof(struct ne2k_pci_card), GFP_KERNEL);
ne2k_card->next = ne2k_card_list;
ne2k_card_list = ne2k_card;
ne2k_card->dev = dev;
ne2k_card->pci_dev = pdev;
}
dev = 0;
cards_found++;
}
return cards_found ? 0 : -ENODEV;
}
__initfunc (static struct device *ne2k_pci_probe1(struct device *dev, long ioaddr, int irq,
int chip_idx))
{
int i;
unsigned char SA_prom[32];
int start_page, stop_page;
int reg0 = inb(ioaddr);
if (reg0 == 0xFF)
return 0;
/* Do a preliminary verification that we have a 8390. */
{
int regd;
outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
regd = inb(ioaddr + 0x0d);
outb(0xff, ioaddr + 0x0d);
outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
if (inb(ioaddr + EN0_COUNTER0) != 0) {
outb(reg0, ioaddr);
outb(regd, ioaddr + 0x0d); /* Restore the old values. */
return 0;
}
}
dev = init_etherdev(dev, 0);
/* Reset card. Who knows what dain-bramaged state it was left in. */
{
unsigned long reset_start_time = jiffies;
outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
/* This looks like a horrible timing loop, but it should never take
more than a few cycles.
*/
while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
/* Limit wait: '2' avoids jiffy roll-over. */
if (jiffies - reset_start_time > 2) {
printk("ne2k-pci: Card failure (no reset ack).\n");
return 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -