📄 mac89x0.c
字号:
/* cs89x0.c: A Crystal Semiconductor CS89[02]0 driver for linux. *//* Written 1996 by Russell Nelson, with reference to skeleton.c written 1993-1994 by Donald Becker. 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 at nelson@crynwr.com, Crynwr Software, 11 Grant St., Potsdam, NY 13676 Changelog: Mike Cruse : mcruse@cti-ltd.com : Changes for Linux 2.0 compatibility. : Added dev_id parameter in net_interrupt(), : request_irq() and free_irq(). Just NULL for now. Mike Cruse : Added MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT macros : in net_open() and net_close() so kerneld would know : that the module is in use and wouldn't eject the : driver prematurely. Mike Cruse : Rewrote init_module() and cleanup_module using 8390.c : as an example. Disabled autoprobing in init_module(), : not a good thing to do to other devices while Linux : is running from all accounts. Alan Cox : Removed 1.2 support, added 2.1 extra counters. David Huggins-Daines <dhd@debian.org> Split this off into mac89x0.c, and gutted it of all parts which are not relevant to the existing CS8900 cards on the Macintosh (i.e. basically the Daynaport CS and LC cards). To be precise: * Removed all the media-detection stuff, because these cards are TP-only. * Lobotomized the ISA interrupt bogosity, because these cards use a hardwired NuBus interrupt and a magic ISAIRQ value in the card. * Basically eliminated everything not relevant to getting the cards minimally functioning on the Macintosh. I might add that these cards are badly designed even from the Mac standpoint, in that Dayna, in their infinite wisdom, used NuBus slot I/O space and NuBus interrupts for these cards, but neglected to provide anything even remotely resembling a NuBus ROM. Therefore we have to probe for them in a brain-damaged ISA-like fashion.*/static char *version ="cs89x0.c:v1.02 11/26/96 Russell Nelson <nelson@crynwr.com>\n";/* ======================= configure the driver here ======================= *//* use 0 for production, 1 for verification, >2 for debug */#ifndef NET_DEBUG#define NET_DEBUG 0#endif/* ======================= end of configuration ======================= *//* Always include 'config.h' first in case the user wants to turn on or override something. */#include <linux/module.h>#define PRINTK(x) printk x/* Sources: Crynwr packet driver epktisa. Crystal Semiconductor data sheets.*/#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 <linux/nubus.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/hwtest.h>#include <asm/macints.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include "cs89x0.h"static unsigned int net_debug = NET_DEBUG;/* Information that need to be kept for each board. */struct net_local { struct net_device_stats stats; int chip_type; /* one of: CS8900, CS8920, CS8920M */ char chip_revision; /* revision letter of the chip ('A'...) */ int send_cmd; /* the propercommand used to send a packet. */ int rx_mode; int curr_rx_cfg; int send_underrun; /* keep track of how many underruns in a row we get */ struct sk_buff *skb;};/* Index to functions, as function prototypes. */extern int mac89x0_probe(struct net_device *dev);#if 0extern void reset_chip(struct net_device *dev);#endifstatic int net_open(struct net_device *dev);static int net_send_packet(struct sk_buff *skb, struct net_device *dev);static void net_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void set_multicast_list(struct net_device *dev);static void net_rx(struct net_device *dev);static int net_close(struct net_device *dev);static struct net_device_stats *net_get_stats(struct net_device *dev);static int set_mac_address(struct net_device *dev, void *addr);/* Example routines you must write ;->. */#define tx_done(dev) 1/* For reading/writing registers ISA-style */static int inlinereadreg_io(struct net_device *dev, int portno){ writew(swab16(portno), dev->base_addr + ADD_PORT); return swab16(readw(dev->base_addr + DATA_PORT));}static void inlinewritereg_io(struct net_device *dev, int portno, int value){ writew(swab16(portno), dev->base_addr + ADD_PORT); writew(swab16(value), dev->base_addr + DATA_PORT);}/* These are for reading/writing registers in shared memory */static int inlinereadreg(struct net_device *dev, int portno){ return swab16(readw(dev->mem_start + portno));}static void inlinewritereg(struct net_device *dev, int portno, int value){ writew(swab16(value), dev->mem_start + portno);}/* Probe for the CS8900 card in slot E. We won't bother looking anywhere else until we have a really good reason to do so. */int __init mac89x0_probe(struct net_device *dev){ static int once_is_enough = 0; struct net_local *lp; static unsigned version_printed = 0; int i, slot; unsigned rev_type = 0; unsigned long ioaddr; unsigned short sig; SET_MODULE_OWNER(dev); if (once_is_enough) return -ENODEV; once_is_enough = 1; /* We might have to parameterize this later */ slot = 0xE; /* Get out now if there's a real NuBus card in slot E */ if (nubus_find_slot(slot, NULL) != NULL) return -ENODEV; /* The pseudo-ISA bits always live at offset 0x300 (gee, wonder why...) */ ioaddr = (unsigned long) nubus_slot_addr(slot) | (((slot&0xf) << 20) + DEFAULTIOBASE); { unsigned long flags; int card_present; save_flags(flags); cli(); card_present = hwreg_present((void*) ioaddr+4) && hwreg_present((void*) ioaddr + DATA_PORT); restore_flags(flags); if (!card_present) return -ENODEV; } writew(0, ioaddr + ADD_PORT); sig = readw(ioaddr + DATA_PORT); if (sig != swab16(CHIP_EISA_ID_SIG)) return -ENODEV; /* Initialize the net_device structure. */ if (dev->priv == NULL) { dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL); memset(dev->priv, 0, sizeof(struct net_local)); } lp = (struct net_local *)dev->priv; /* Fill in the 'dev' fields. */ dev->base_addr = ioaddr; dev->mem_start = (unsigned long) nubus_slot_addr(slot) | (((slot&0xf) << 20) + MMIOBASE); dev->mem_end = dev->mem_start + 0x1000; /* Turn on shared memory */ writereg_io(dev, PP_BusCTL, MEMORY_ON); /* get the chip type */ rev_type = readreg(dev, PRODUCT_ID_ADD); lp->chip_type = rev_type &~ REVISON_BITS; lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A'; /* Check the chip type and revision in order to set the correct send command CS8920 revision C and CS8900 revision F can use the faster send. */ lp->send_cmd = TX_AFTER_381; if (lp->chip_type == CS8900 && lp->chip_revision >= 'F') lp->send_cmd = TX_NOW; if (lp->chip_type != CS8900 && lp->chip_revision >= 'C') lp->send_cmd = TX_NOW; if (net_debug && version_printed++ == 0) printk(version); printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#8lx", dev->name, lp->chip_type==CS8900?'0':'2', lp->chip_type==CS8920M?"M":"", lp->chip_revision, dev->base_addr); /* Try to read the MAC address */ if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) { printk("\nmac89x0: No EEPROM, giving up now.\n"); return -ENODEV; } else { for (i = 0; i < ETH_ALEN; i += 2) { /* Big-endian (why??!) */ unsigned short s = readreg(dev, PP_IA + i); dev->dev_addr[i] = s >> 8; dev->dev_addr[i+1] = s & 0xff; } } dev->irq = SLOT2IRQ(slot); printk(" IRQ %d ADDR ", dev->irq); /* print the ethernet address. */ for (i = 0; i < ETH_ALEN; i++) printk("%2.2x%s", dev->dev_addr[i], ((i < ETH_ALEN-1) ? ":" : "")); dev->open = net_open; dev->stop = net_close; dev->hard_start_xmit = net_send_packet; dev->get_stats = net_get_stats; dev->set_multicast_list = &set_multicast_list; dev->set_mac_address = &set_mac_address; /* Fill in the fields of the net_device structure with ethernet values. */ ether_setup(dev); printk("\n"); return 0;}#if 0/* This is useful for something, but I don't know what yet. */void __init reset_chip(struct net_device *dev){ int reset_start_time; writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET); /* wait 30 ms */ current->state = TASK_INTERRUPTIBLE; schedule_timeout(30*HZ/1000); /* Wait until the chip is reset */ reset_start_time = jiffies; while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - reset_start_time < 2) ;}#endif/* Open/initialize the board. This is called (in the current kernel) sometime after booting when the 'ifconfig' program is run. This routine should set everything up anew at each open, even registers that "should" only need to be set once at boot, so that there is non-reboot way to recover if something goes wrong. */static intnet_open(struct net_device *dev){ struct net_local *lp = (struct net_local *)dev->priv; int i; /* Disable the interrupt for now */ writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL) & ~ENABLE_IRQ); /* Grab the interrupt */ if (request_irq(dev->irq, &net_interrupt, 0, "cs89x0", dev)) return -EAGAIN; /* Set up the IRQ - Apparently magic */ if (lp->chip_type == CS8900) writereg(dev, PP_CS8900_ISAINT, 0); else writereg(dev, PP_CS8920_ISAINT, 0); /* set the Ethernet address */ for (i=0; i < ETH_ALEN/2; i++) writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -