Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

pcnet32.c

Go to the documentation of this file.
00001 /* pcnet32.c: An AMD PCnet32 ethernet driver for linux. */
00002 /*
00003  *      Copyright 1996-1999 Thomas Bogendoerfer
00004  * 
00005  *      Derived from the lance driver written 1993,1994,1995 by Donald Becker.
00006  * 
00007  *      Copyright 1993 United States Government as represented by the
00008  *      Director, National Security Agency.
00009  * 
00010  *      This software may be used and distributed according to the terms
00011  *      of the GNU Public License, incorporated herein by reference.
00012  *
00013  *      This driver is for PCnet32 and PCnetPCI based ethercards
00014  */
00015 
00016 static const char *version = "pcnet32.c:v1.25kf 26.9.1999 tsbogend@alpha.franken.de\n";
00017 
00018 #include <linux/config.h>
00019 #include <linux/module.h>
00020 #ifdef MODVERSIONS
00021 #include <linux/modversions.h>
00022 #endif
00023 
00024 #include <linux/kernel.h>
00025 #include <linux/sched.h>
00026 #include <linux/string.h>
00027 #include <linux/ptrace.h>
00028 #include <linux/errno.h>
00029 #include <linux/ioport.h>
00030 #include <linux/malloc.h>
00031 #include <linux/interrupt.h>
00032 #include <linux/pci.h>
00033 #include <linux/delay.h>
00034 #include <linux/init.h>
00035 #include <asm/bitops.h>
00036 #include <asm/io.h>
00037 #include <asm/dma.h>
00038 
00039 #include <linux/netdevice.h>
00040 #include <linux/etherdevice.h>
00041 #include <linux/skbuff.h>
00042 #include <asm/spinlock.h>
00043 
00044 static unsigned int pcnet32_portlist[] __initdata = {0x300, 0x320, 0x340, 0x360, 0};
00045 
00046 static int pcnet32_debug = 1;
00047 static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
00048 
00049 #ifdef MODULE
00050 static struct device *pcnet32_dev = NULL;
00051 #endif
00052 
00053 static const int max_interrupt_work = 80;
00054 static const int rx_copybreak = 200;
00055 
00056 #define PORT_AUI      0x00
00057 #define PORT_10BT     0x01
00058 #define PORT_GPSI     0x02
00059 #define PORT_MII      0x03
00060 
00061 #define PORT_PORTSEL  0x03
00062 #define PORT_ASEL     0x04
00063 #define PORT_100      0x40
00064 #define PORT_FD       0x80
00065 
00066 
00067 /*
00068  * table to translate option values from tulip
00069  * to internal options
00070  */
00071 static unsigned char options_mapping[] = {
00072     PORT_ASEL,                     /*  0 Auto-select      */
00073     PORT_AUI,                      /*  1 BNC/AUI          */
00074     PORT_AUI,                      /*  2 AUI/BNC          */ 
00075     PORT_ASEL,                     /*  3 not supported    */
00076     PORT_10BT | PORT_FD,           /*  4 10baseT-FD       */
00077     PORT_ASEL,                     /*  5 not supported    */
00078     PORT_ASEL,                     /*  6 not supported    */
00079     PORT_ASEL,                     /*  7 not supported    */
00080     PORT_ASEL,                     /*  8 not supported    */
00081     PORT_MII,                      /*  9 MII 10baseT      */
00082     PORT_MII | PORT_FD,            /* 10 MII 10baseT-FD   */
00083     PORT_MII,                      /* 11 MII (autosel)    */
00084     PORT_10BT,                     /* 12 10BaseT          */
00085     PORT_MII | PORT_100,           /* 13 MII 100BaseTx    */
00086     PORT_MII | PORT_100 | PORT_FD, /* 14 MII 100BaseTx-FD */
00087     PORT_ASEL                      /* 15 not supported    */
00088 };
00089 
00090 #define MAX_UNITS 8
00091 static int options[MAX_UNITS] = {0, };
00092 static int full_duplex[MAX_UNITS] = {0, };
00093 
00094 /*
00095  *                              Theory of Operation
00096  * 
00097  * This driver uses the same software structure as the normal lance
00098  * driver. So look for a verbose description in lance.c. The differences
00099  * to the normal lance driver is the use of the 32bit mode of PCnet32
00100  * and PCnetPCI chips. Because these chips are 32bit chips, there is no
00101  * 16MB limitation and we don't need bounce buffers.
00102  */
00103  
00104 /*
00105  * History:
00106  * v0.01:  Initial version
00107  *         only tested on Alpha Noname Board
00108  * v0.02:  changed IRQ handling for new interrupt scheme (dev_id)
00109  *         tested on a ASUS SP3G
00110  * v0.10:  fixed an odd problem with the 79C974 in a Compaq Deskpro XL
00111  *         looks like the 974 doesn't like stopping and restarting in a
00112  *         short period of time; now we do a reinit of the lance; the
00113  *         bug was triggered by doing ifconfig eth0 <ip> broadcast <addr>
00114  *         and hangs the machine (thanks to Klaus Liedl for debugging)
00115  * v0.12:  by suggestion from Donald Becker: Renamed driver to pcnet32,
00116  *         made it standalone (no need for lance.c)
00117  * v0.13:  added additional PCI detecting for special PCI devices (Compaq)
00118  * v0.14:  stripped down additional PCI probe (thanks to David C Niemi
00119  *         and sveneric@xs4all.nl for testing this on their Compaq boxes)
00120  * v0.15:  added 79C965 (VLB) probe
00121  *         added interrupt sharing for PCI chips
00122  * v0.16:  fixed set_multicast_list on Alpha machines
00123  * v0.17:  removed hack from dev.c; now pcnet32 uses ethif_probe in Space.c
00124  * v0.19:  changed setting of autoselect bit
00125  * v0.20:  removed additional Compaq PCI probe; there is now a working one
00126  *         in arch/i386/bios32.c
00127  * v0.21:  added endian conversion for ppc, from work by cort@cs.nmt.edu
00128  * v0.22:  added printing of status to ring dump
00129  * v0.23:  changed enet_statistics to net_devive_stats
00130  * v0.90:  added multicast filter
00131  *         added module support
00132  *         changed irq probe to new style
00133  *         added PCnetFast chip id
00134  *         added fix for receive stalls with Intel saturn chipsets
00135  *         added in-place rx skbs like in the tulip driver
00136  *         minor cleanups
00137  * v0.91:  added PCnetFast+ chip id
00138  *         back port to 2.0.x
00139  * v1.00:  added some stuff from Donald Becker's 2.0.34 version
00140  *         added support for byte counters in net_dev_stats
00141  * v1.01:  do ring dumps, only when debugging the driver
00142  *         increased the transmit timeout
00143  * v1.02:  fixed memory leak in pcnet32_init_ring()
00144  * v1.10:  workaround for stopped transmitter
00145  *         added port selection for modules
00146  *         detect special T1/E1 WAN card and setup port selection
00147  * v1.11:  fixed wrong checking of Tx errors
00148  * v1.20:  added check of return value kmalloc (cpeterso@cs.washington.edu)
00149  *         added save original kmalloc addr for freeing (mcr@solidum.com)
00150  *         added support for PCnetHome chip (joe@MIT.EDU)
00151  *         rewritten PCI card detection
00152  *         added dwio mode to get driver working on some PPC machines
00153  * v1.21:  added mii selection and mii ioctl
00154  * v1.22:  changed pci scanning code to make PPC people happy
00155  *         fixed switching to 32bit mode in pcnet32_open() (thanks
00156  *         to Michael Richard <mcr@solidum.com> for noticing this one)
00157  *         added sub vendor/device id matching (thanks again to 
00158  *         Michael Richard <mcr@solidum.com>)
00159  *         added chip id for 79c973/975 (thanks to Zach Brown <zab@zabbo.net>)
00160  * v1.23   fixed small bug, when manual selecting MII speed/duplex
00161  * v1.24   Applied Thomas' patch to use TxStartPoint and thus decrease TxFIFO
00162  *         underflows.  Added tx_start_pt module parameter. Increased
00163  *         TX_RING_SIZE from 16 to 32.  Added #ifdef'd code to use DXSUFLO
00164  *         for FAST[+] chipsets. <kaf@fc.hp.com>
00165  * v1.24ac Added SMP spinlocking - Alan Cox <alan@redhat.com>
00166  * v1.25kf Added No Interrupt on successful Tx for some Tx's <kaf@fc.hp.com>
00167  */
00168 
00169 
00170 /*
00171  * Set the number of Tx and Rx buffers, using Log_2(# buffers).
00172  * Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
00173  * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
00174  */
00175 #ifndef PCNET32_LOG_TX_BUFFERS
00176 #define PCNET32_LOG_TX_BUFFERS 4
00177 #define PCNET32_LOG_RX_BUFFERS 5
00178 #endif
00179 
00180 #define TX_RING_SIZE                    (1 << (PCNET32_LOG_TX_BUFFERS))
00181 #define TX_RING_MOD_MASK                (TX_RING_SIZE - 1)
00182 #define TX_RING_LEN_BITS                ((PCNET32_LOG_TX_BUFFERS) << 12)
00183 
00184 #define RX_RING_SIZE                    (1 << (PCNET32_LOG_RX_BUFFERS))
00185 #define RX_RING_MOD_MASK                (RX_RING_SIZE - 1)
00186 #define RX_RING_LEN_BITS                ((PCNET32_LOG_RX_BUFFERS) << 4)
00187 
00188 #define PKT_BUF_SZ              1544
00189 
00190 /* Offsets from base I/O address. */
00191 #define PCNET32_WIO_RDP         0x10
00192 #define PCNET32_WIO_RAP         0x12
00193 #define PCNET32_WIO_RESET       0x14
00194 #define PCNET32_WIO_BDP         0x16
00195 
00196 #define PCNET32_DWIO_RDP        0x10
00197 #define PCNET32_DWIO_RAP        0x14
00198 #define PCNET32_DWIO_RESET      0x18
00199 #define PCNET32_DWIO_BDP        0x1C
00200 
00201 #define PCNET32_TOTAL_SIZE 0x20
00202 
00203 /* some PCI ids */
00204 #ifndef PCI_DEVICE_ID_AMD_LANCE
00205 #define PCI_VENDOR_ID_AMD             0x1022
00206 #define PCI_DEVICE_ID_AMD_LANCE       0x2000
00207 #endif
00208 #ifndef PCI_DEVICE_ID_AMD_PCNETHOME
00209 #define PCI_DEVICE_ID_AMD_PCNETHOME   0x2001
00210 #endif
00211 
00212 
00213 #define CRC_POLYNOMIAL_LE 0xedb88320UL  /* Ethernet CRC, little endian */
00214 
00215 /* The PCNET32 Rx and Tx ring descriptors. */
00216 struct pcnet32_rx_head {
00217     u32 base;
00218     s16 buf_length;
00219     s16 status;    
00220     u32 msg_length;
00221     u32 reserved;
00222 };
00223         
00224 struct pcnet32_tx_head {
00225     u32 base;
00226     s16 length;
00227     s16 status;
00228     u32 misc;
00229     u32 reserved;
00230 };
00231 
00232 /* The PCNET32 32-Bit initialization block, described in databook. */
00233 struct pcnet32_init_block {
00234     u16 mode;
00235     u16 tlen_rlen;
00236     u8  phys_addr[6];
00237     u16 reserved;
00238     u32 filter[2];
00239     /* Receive and transmit ring base, along with extra bits. */    
00240     u32 rx_ring;
00241     u32 tx_ring;
00242 };
00243 
00244 /* PCnet32 access functions */
00245 struct pcnet32_access {
00246     u16 (*read_csr)(unsigned long, int);
00247     void (*write_csr)(unsigned long, int, u16);
00248     u16 (*read_bcr)(unsigned long, int);
00249     void (*write_bcr)(unsigned long, int, u16);
00250     u16 (*read_rap)(unsigned long);
00251     void (*write_rap)(unsigned long, u16);
00252     void (*reset)(unsigned long);
00253 };
00254 
00255 struct pcnet32_private {
00256     /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */
00257     struct pcnet32_rx_head   rx_ring[RX_RING_SIZE];
00258     struct pcnet32_tx_head   tx_ring[TX_RING_SIZE];
00259     struct pcnet32_init_block   init_block;
00260     const char *name;
00261     /* The saved address of a sent-in-place packet/buffer, for skfree(). */
00262     struct sk_buff *tx_skbuff[TX_RING_SIZE];
00263     struct sk_buff *rx_skbuff[RX_RING_SIZE];
00264     struct pcnet32_access a;
00265     void *origmem;
00266     spinlock_t lock;                            /* Guard lock */
00267     unsigned int cur_rx, cur_tx;                /* The next free ring entry */
00268     unsigned int dirty_rx, dirty_tx;            /* The ring entries to be free()ed. */
00269     struct net_device_stats stats;
00270     char tx_full;
00271     int  options;
00272     int  shared_irq:1,                      /* shared irq possible */
00273          ltint:1,
00274 #ifdef DO_DXSUFLO
00275          dxsuflo:1,                         /* disable transmit stop on uflo */
00276 #endif
00277          full_duplex:1,                     /* full duplex possible */
00278          mii:1;                             /* mii port available */
00279 #ifdef MODULE
00280     struct device *next;
00281 #endif    
00282 };
00283 
00284 int  pcnet32_probe(struct device *);
00285 static int  pcnet32_probe1(struct device *, unsigned long, unsigned char, int, int);
00286 static int  pcnet32_open(struct device *);
00287 static int  pcnet32_init_ring(struct device *);
00288 static int  pcnet32_start_xmit(struct sk_buff *, struct device *);
00289 static int  pcnet32_rx(struct device *);
00290 static void pcnet32_interrupt(int, void *, struct pt_regs *);
00291 static int  pcnet32_close(struct device *);
00292 static struct net_device_stats *pcnet32_get_stats(struct device *);
00293 static void pcnet32_set_multicast_list(struct device *);
00294 #ifdef HAVE_PRIVATE_IOCTL
00295 static int  pcnet32_mii_ioctl(struct device *, struct ifreq *, int);
00296 #endif
00297 
00298 enum pci_flags_bit {
00299     PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
00300     PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
00301 };
00302 
00303 struct pcnet32_pci_id_info {
00304     const char *name;
00305     u16 vendor_id, device_id, svid, sdid, flags;
00306     int io_size;
00307     int (*probe1) (struct device *, unsigned long, unsigned char, int, int);
00308 };
00309 
00310 static struct pcnet32_pci_id_info pcnet32_tbl[] = {
00311     { "AMD PCnetPCI series",
00312         PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE, 0, 0,
00313         PCI_USES_IO|PCI_USES_MASTER, PCNET32_TOTAL_SIZE,
00314         pcnet32_probe1},
00315     { "AMD PCnetPCI series (IBM)",
00316         PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE, 0x1014, 0x2000,
00317         PCI_USES_IO|PCI_USES_MASTER, PCNET32_TOTAL_SIZE,
00318         pcnet32_probe1},
00319     /* Someone apparently got their vendor id wrong ..
00320        reported in an IBM box */
00321     { "AMD PCnetPCI series (IBM)",
00322         0x1023, 0x2000, 0, 0,
00323         PCI_USES_IO|PCI_USES_MASTER, PCNET32_TOTAL_SIZE,
00324         pcnet32_probe1},
00325     { "AMD PCnetHome series",
00326         PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_PCNETHOME, 0, 0,
00327         PCI_USES_IO|PCI_USES_MASTER, PCNET32_TOTAL_SIZE,
00328         pcnet32_probe1},
00329     {0,}
00330 };
00331 
00332 static u16 pcnet32_wio_read_csr (unsigned long addr, int index)
00333 {
00334     outw (index, addr+PCNET32_WIO_RAP);
00335     return inw (addr+PCNET32_WIO_RDP);
00336 }
00337 
00338 static void pcnet32_wio_write_csr (unsigned long addr, int index, u16 val)
00339 {
00340     outw (index, addr+PCNET32_WIO_RAP);
00341     outw (val, addr+PCNET32_WIO_RDP);
00342 }
00343 
00344 static u16 pcnet32_wio_read_bcr (unsigned long addr, int index)
00345 {
00346     outw (index, addr+PCNET32_WIO_RAP);
00347     return inw (addr+PCNET32_WIO_BDP);
00348 }
00349 
00350 static void pcnet32_wio_write_bcr (unsigned long addr, int index, u16 val)
00351 {
00352     outw (index, addr+PCNET32_WIO_RAP);
00353     outw (val, addr+PCNET32_WIO_BDP);
00354 }
00355 
00356 static u16 pcnet32_wio_read_rap (unsigned long addr)
00357 {
00358     return inw (addr+PCNET32_WIO_RAP);
00359 }
00360 
00361 static void pcnet32_wio_write_rap (unsigned long addr, u16 val)
00362 {
00363     outw (val, addr+PCNET32_WIO_RAP);
00364 }
00365 
00366 static void pcnet32_wio_reset (unsigned long addr)
00367 {
00368     inw (addr+PCNET32_WIO_RESET);
00369 }
00370 
00371 static int pcnet32_wio_check (unsigned long addr)
00372 {
00373     outw (88, addr+PCNET32_WIO_RAP);
00374     return (inw (addr+PCNET32_WIO_RAP) == 88);
00375 }
00376 
00377 static struct pcnet32_access pcnet32_wio = {
00378     pcnet32_wio_read_csr,
00379     pcnet32_wio_write_csr,
00380     pcnet32_wio_read_bcr,
00381     pcnet32_wio_write_bcr,
00382     pcnet32_wio_read_rap,
00383     pcnet32_wio_write_rap,
00384     pcnet32_wio_reset
00385 };
00386 
00387 static u16 pcnet32_dwio_read_csr (unsigned long addr, int index)
00388 {
00389     outl (index, addr+PCNET32_DWIO_RAP);
00390     return (inl (addr+PCNET32_DWIO_RDP) & 0xffff);
00391 }
00392 
00393 static void pcnet32_dwio_write_csr (unsigned long addr, int index, u16 val)
00394 {
00395     outl (index, addr+PCNET32_DWIO_RAP);
00396     outl (val, addr+PCNET32_DWIO_RDP);
00397 }
00398 
00399 static u16 pcnet32_dwio_read_bcr (unsigned long addr, int index)
00400 {
00401     outl (index, addr+PCNET32_DWIO_RAP);
00402     return (inl (addr+PCNET32_DWIO_BDP) & 0xffff);
00403 }
00404 
00405 static void pcnet32_dwio_write_bcr (unsigned long addr, int index, u16 val)
00406 {
00407     outl (index, addr+PCNET32_DWIO_RAP);
00408     outl (val, addr+PCNET32_DWIO_BDP);
00409 }
00410 
00411 static u16 pcnet32_dwio_read_rap (unsigned long addr)
00412 {
00413     return (inl (addr+PCNET32_DWIO_RAP) & 0xffff);
00414 }
00415 
00416 static void pcnet32_dwio_write_rap (unsigned long addr, u16 val)
00417 {
00418     outl (val, addr+PCNET32_DWIO_RAP);
00419 }
00420 
00421 static void pcnet32_dwio_reset (unsigned long addr)
00422 {
00423     inl (addr+PCNET32_DWIO_RESET);
00424 }
00425 
00426 static int pcnet32_dwio_check (unsigned long addr)
00427 {
00428     outl (88, addr+PCNET32_DWIO_RAP);
00429     return (inl (addr+PCNET32_DWIO_RAP) == 88);
00430 }
00431 
00432 static struct pcnet32_access pcnet32_dwio = {
00433     pcnet32_dwio_read_csr,
00434     pcnet32_dwio_write_csr,
00435     pcnet32_dwio_read_bcr,
00436     pcnet32_dwio_write_bcr,
00437     pcnet32_dwio_read_rap,
00438     pcnet32_dwio_write_rap,
00439     pcnet32_dwio_reset
00440 
00441 };
00442 
00443 
00444 
00445 int __init pcnet32_probe (struct device *dev)
00446 {
00447     unsigned long ioaddr = dev ? dev->base_addr: 0;
00448     unsigned int  irq_line = dev ? dev->irq : 0;
00449     int *port;
00450     int cards_found = 0;
00451     
00452     
00453 #ifndef __powerpc__
00454     if (ioaddr > 0x1ff) {
00455         if (check_region(ioaddr, PCNET32_TOTAL_SIZE) == 0)
00456             return pcnet32_probe1(dev, ioaddr, irq_line, 0, 0);
00457         else
00458             return ENODEV;
00459     } else
00460 #endif
00461         if(ioaddr != 0)
00462             return ENXIO;
00463     
00464 #if defined(CONFIG_PCI)
00465     if (pci_present()) {
00466         struct pci_dev *pdev = NULL;
00467         
00468         printk("pcnet32.c: PCI bios is present, checking for devices...\n");
00469         while ((pdev = pci_find_class (PCI_CLASS_NETWORK_ETHERNET<<8, pdev))) {
00470             u16 pci_command;
00471             int chip_idx;
00472             u16 sdid,svid;
00473 
00474             pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &svid);
00475             pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sdid);
00476             for (chip_idx = 0; pcnet32_tbl[chip_idx].vendor_id; chip_idx++)
00477                 if ((pdev->vendor == pcnet32_tbl[chip_idx].vendor_id) &&
00478                     (pdev->device == pcnet32_tbl[chip_idx].device_id) &&
00479                     (pcnet32_tbl[chip_idx].svid == 0 || 
00480                      (svid == pcnet32_tbl[chip_idx].svid)) &&
00481                     (pcnet32_tbl[chip_idx].sdid == 0 || 
00482                      (sdid == pcnet32_tbl[chip_idx].sdid)))
00483                     break;
00484             if (pcnet32_tbl[chip_idx].vendor_id == 0)
00485                 continue;
00486             
00487             ioaddr = pdev->base_address[0] & PCI_BASE_ADDRESS_IO_MASK;
00488 #if defined(ADDR_64BITS) && defined(__alpha__)
00489             ioaddr |= ((long)pdev->base_address[1]) << 32;
00490 #endif
00491             irq_line = pdev->irq;
00492             
00493             /* Avoid already found cards from previous pcnet32_probe() calls */
00494             if ((pcnet32_tbl[chip_idx].flags & PCI_USES_IO) &&
00495                 check_region(ioaddr, pcnet32_tbl[chip_idx].io_size))
00496                 continue;
00497 
00498             /* PCI Spec 2.1 states that it is either the driver or PCI card's
00499              * responsibility to set the PCI Master Enable Bit if needed.
00500              *  (From Mark Stockton <marks@schooner.sys.hou.compaq.com>)
00501              */
00502             pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
00503             if ( ! (pci_command & PCI_COMMAND_MASTER)) {
00504                 printk("PCI Master Bit has not been set. Setting...\n");
00505                 pci_command |= PCI_COMMAND_MASTER|PCI_COMMAND_IO;
00506                 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
00507             }
00508             printk("Found PCnet/PCI at %#lx, irq %d.\n", ioaddr, irq_line);
00509             
00510             if (pcnet32_tbl[chip_idx].probe1(dev, ioaddr, irq_line, 1, cards_found) == 0) {
00511                 cards_found++;
00512                 dev = NULL;
00513             }
00514         }
00515     } else 
00516 #endif  /* defined(CONFIG_PCI) */
00517     
00518     /* now look for PCnet32 VLB cards */
00519     for (port = pcnet32_portlist; *port; port++) {
00520         unsigned long ioaddr = *port;
00521         
00522         if ( check_region(ioaddr, PCNET32_TOTAL_SIZE) == 0) {
00523             /* check if there is really a pcnet chip on that ioaddr */
00524             if ((inb(ioaddr + 14) == 0x57) &&
00525                 (inb(ioaddr + 15) == 0x57) &&
00526                 (pcnet32_probe1(dev, ioaddr, 0, 0, 0) == 0))
00527                 cards_found++;
00528         }
00529     }
00530     return cards_found ? 0: ENODEV;
00531 }
00532 
00533 
00534 /* pcnet32_probe1 */
00535 static int __init
00536 pcnet32_probe1(struct device *dev, unsigned long ioaddr, unsigned char irq_line, int shared, int card_idx)
00537 {
00538     struct pcnet32_private *lp;
00539     int i,media,fdx = 0, mii = 0;
00540 #ifdef DO_DXSUFLO
00541     int dxsuflo = 0;
00542 #endif
00543     int ltint = 0;
00544     int chip_version;
00545     char *chipname;
00546     char *priv;
00547     struct pcnet32_access *a;
00548 
00549     /* reset the chip */
00550     pcnet32_dwio_reset(ioaddr);
00551     pcnet32_wio_reset(ioaddr);
00552 
00553     if (pcnet32_wio_read_csr (ioaddr, 0) == 4 && pcnet32_wio_check (ioaddr)) {
00554         a = &pcnet32_wio;
00555     } else {
00556         if (pcnet32_dwio_read_csr (ioaddr, 0) == 4 && pcnet32_dwio_check(ioaddr)) {
00557             a = &pcnet32_dwio;
00558         } else
00559             return ENODEV;
00560     }
00561 
00562 
00563     chip_version = a->read_csr (ioaddr, 88) | (a->read_csr (ioaddr,89) << 16);
00564     if (pcnet32_debug > 2)
00565         printk("  PCnet chip version is %#x.\n", chip_version);
00566     if ((chip_version & 0xfff) != 0x003)
00567         return ENODEV;
00568     chip_version = (chip_version >> 12) & 0xffff;
00569 
00570     switch (chip_version) {
00571      case 0x2420:
00572         chipname = "PCnet/PCI 79C970";
00573         break;
00574      case 0x2430:
00575         if (shared)
00576             chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
00577         else
00578             chipname = "PCnet/32 79C965";
00579         break;
00580      case 0x2621:
00581         chipname = "PCnet/PCI II 79C970A";
00582         fdx = 1;
00583         break;
00584      case 0x2623:
00585         chipname = "PCnet/FAST 79C971";
00586         /* To prevent Tx FIFO underflows ... (may increase Tx latency) */
00587         /* Set BCR18:NOUFLO to not start Tx until reach Tx start point */
00588         /* Looks like EEPROM sets BCR18:5/6 for BurstWrite/Read */
00589         a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0800));
00590         /* Set CSR80:XMTSP, Tx start point = 20|64|128|248 bytes or size of frame */
00591         i = a->read_csr(ioaddr, 80) & ~0x0C00; /* Clear bits we are touching */
00592         a->write_csr(ioaddr, 80, i | (tx_start << 10));
00593         fdx = 1; mii = 1;
00594 #ifdef DO_DXSUFLO
00595         dxsuflo = 1;
00596 #endif
00597         ltint = 1;
00598         break;
00599      case 0x2624:
00600         chipname = "PCnet/FAST+ 79C972";
00601         /* To prevent Tx FIFO underflows ... (may increase Tx latency) */
00602         /* Set BCR18:NOUFLO to not start Tx until reach Tx start point */
00603         /* Looks like EEPROM sets BCR18:5/6 for BurstWrite/Read */
00604         a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0800));
00605         /* Set CSR80:XMTSP, Tx start point = 20|64|128|220 bytes or size of frame */
00606         i = a->read_csr(ioaddr, 80) & ~0x0C00; /* Clear bits we are touching */
00607         a->write_csr(ioaddr, 80, i | (tx_start << 10));
00608         fdx = 1; mii = 1;
00609 #ifdef DO_DXSUFLO
00610         dxsuflo = 1;
00611 #endif
00612         ltint = 1;
00613         break;
00614      case 0x2625:
00615         chipname = "PCnet/FAST III 79C973";
00616         fdx = 1; mii = 1;
00617         break;
00618      case 0x2626:
00619         chipname = "PCnet/Home 79C978";
00620         fdx = 1;
00621         /* 
00622          * This is based on specs published at www.amd.com.  This section
00623          * assumes that a card with a 79C978 wants to go into 1Mb HomePNA
00624          * mode.  The 79C978 can also go into standard ethernet, and there
00625          * probably should be some sort of module option to select the
00626          * mode by which the card should operate
00627          */
00628         /* switch to home wiring mode */
00629         media = a->read_bcr (ioaddr, 49);
00630         if (pcnet32_debug > 2)
00631             printk("pcnet32: pcnet32 media value %#x.\n",  media);
00632         media &= ~3;
00633         media |= 1;
00634         if (pcnet32_debug > 2)
00635             printk("pcnet32: pcnet32 media reset to %#x.\n",  media);
00636         a->write_bcr (ioaddr, 49, media);
00637         break;
00638      case 0x2627:
00639         chipname = "PCnet/FAST III 79C975";
00640         fdx = 1; mii = 1;
00641         break;
00642      default:
00643         printk("pcnet32: PCnet version %#x, no PCnet32 chip.\n",chip_version);
00644         return ENODEV;
00645     }
00646     
00647     dev = init_etherdev(dev, 0);
00648 
00649     printk(KERN_INFO "%s: %s at %#3lx,", dev->name, chipname, ioaddr);
00650 
00651     /* There is a 16 byte station address PROM at the base address.
00652      The first six bytes are the station address. */
00653     for (i = 0; i < 6; i++)
00654       printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
00655 
00656     if (((chip_version + 1) & 0xfffe) == 0x2624) { /* Version 0x2623 or 0x2624 */
00657         i = a->read_csr(ioaddr, 80) & 0x0C00;  /* Check tx_start_pt */
00658         printk("\n    tx_start_pt(0x%04x):",i);
00659         switch(i>>10) {
00660             case 0: printk("  20 bytes,"); break;
00661             case 1: printk("  64 bytes,"); break;
00662             case 2: printk(" 128 bytes,"); break;
00663             case 3: printk("~220 bytes,"); break;
00664         }
00665         i = a->read_bcr(ioaddr, 18);  /* Check Burst/Bus control */
00666         printk(" BCR18(%x):",i&0xffff);
00667         if (i & (1<<5)) printk("BurstWrEn ");
00668         if (i & (1<<6)) printk("BurstRdEn ");
00669         if (i & (1<<7)) printk("DWordIO ");
00670         if (i & (1<<11)) printk("NoUFlow ");
00671         i = a->read_bcr(ioaddr, 25);
00672         printk("\n    SRAMSIZE=0x%04x,",i<<8);
00673         i = a->read_bcr(ioaddr, 26);
00674         printk(" SRAM_BND=0x%04x,",i<<8);
00675         i = a->read_bcr(ioaddr, 27);
00676         if (i & (1<<14)) printk("LowLatRx,");
00677     }
00678 
00679     dev->base_addr = ioaddr;
00680     request_region(ioaddr, PCNET32_TOTAL_SIZE, chipname);
00681     
00682     if ((priv = kmalloc(sizeof(*lp)+15,GFP_KERNEL)) == NULL)
00683         return ENOMEM;
00684 
00685     /*
00686      * Make certain the data structures used by
00687      * the PCnet32 are 16byte aligned
00688       */
00689     lp = (struct pcnet32_private *)(((unsigned long)priv+15) & ~15);
00690       
00691     memset(lp, 0, sizeof(*lp));
00692     
00693     spin_lock_init(&lp->lock);
00694     
00695     dev->priv = lp;
00696     lp->name = chipname;
00697     lp->shared_irq = shared;
00698     lp->full_duplex = fdx;
00699 #ifdef DO_DXSUFLO
00700     lp->dxsuflo = dxsuflo;
00701 #endif
00702     lp->ltint = ltint;
00703     lp->mii = mii;
00704     if (options[card_idx] > sizeof (options_mapping))
00705         lp->options = PORT_ASEL;
00706     else
00707         lp->options = options_mapping[options[card_idx]];
00708     
00709     if (fdx && !(lp->options & PORT_ASEL) && full_duplex[card_idx])
00710         lp->options |= PORT_FD;
00711     
00712     lp->origmem = priv;
00713     lp->a = *a;
00714     
00715     /* detect special T1/E1 WAN card by checking for MAC address */
00716     if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0 && dev->dev_addr[2] == 0x75)
00717         lp->options = PORT_FD | PORT_GPSI;
00718 
00719     lp->init_block.mode = le16_to_cpu(0x0003);  /* Disable Rx and Tx. */
00720     lp->init_block.tlen_rlen = le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS); 
00721     for (i = 0; i < 6; i++)
00722       lp->init_block.phys_addr[i] = dev->dev_addr[i];
00723     lp->init_block.filter[0] = 0x00000000;
00724     lp->init_block.filter[1] = 0x00000000;
00725     lp->init_block.rx_ring = (u32)le32_to_cpu(virt_to_bus(lp->rx_ring));
00726     lp->init_block.tx_ring = (u32)le32_to_cpu(virt_to_bus(lp->tx_ring));
00727     
00728     /* switch pcnet32 to 32bit mode */
00729     a->write_bcr (ioaddr, 20, 2);
00730 
00731     a->write_csr (ioaddr, 1, virt_to_bus(&lp->init_block) & 0xffff);
00732     a->write_csr (ioaddr, 2, virt_to_bus(&lp->init_block) >> 16);
00733     
00734     if (irq_line) {
00735         dev->irq = irq_line;
00736     }
00737     
00738     if (dev->irq >= 2)
00739         printk(" assigned IRQ %d.\n", dev->irq);
00740     else {
00741         unsigned long irq_mask = probe_irq_on();
00742         
00743         /*
00744          * To auto-IRQ we enable the initialization-done and DMA error
00745          * interrupts. For ISA boards we get a DMA error, but VLB and PCI
00746          * boards will work.
00747          */
00748         /* Trigger an initialization just for the interrupt. */
00749         a->write_csr (ioaddr, 0, 0x41);
00750         mdelay (1);
00751         
00752         dev->irq = probe_irq_off (irq_mask);
00753         if (dev->irq)
00754           printk(", probed IRQ %d.\n", dev->irq);
00755         else {
00756             printk(", failed to detect IRQ line.\n");
00757             return ENODEV;
00758         }
00759     }
00760 
00761     if (pcnet32_debug > 0)
00762         printk(version);
00763     
00764     /* The PCNET32-specific entries in the device structure. */
00765     dev->open = &pcnet32_open;
00766     dev->hard_start_xmit = &pcnet32_start_xmit;
00767     dev->stop = &pcnet32_close;
00768     dev->get_stats = &pcnet32_get_stats;
00769     dev->set_multicast_list = &pcnet32_set_multicast_list;
00770 #ifdef HAVE_PRIVATE_IOCTL
00771     dev->do_ioctl = &pcnet32_mii_ioctl;
00772 #endif
00773 
00774     
00775 #ifdef MODULE
00776     lp->next = pcnet32_dev;
00777     pcnet32_dev = dev;
00778 #endif  
00779 
00780     /* Fill in the generic fields of the device structure. */
00781     ether_setup(dev);
00782     return 0;
00783 }
00784 
00785 
00786 static int
00787 pcnet32_open(struct device *dev)
00788 {
00789     struct pcnet32_private *lp = (struct pcnet32_private *)dev->priv;
00790     unsigned long ioaddr = dev->base_addr;
00791     u16 val;
00792     int i;
00793 
00794     if (dev->irq == 0 ||
00795         request_irq(dev->irq, &pcnet32_interrupt,
00796                     lp->shared_irq ? SA_SHIRQ : 0, lp->name, (void *)dev)) {
00797         return -EAGAIN;
00798     }
00799 
00800     /* Reset the PCNET32 */
00801     lp->a.reset (ioaddr);
00802 
00803     /* switch pcnet32 to 32bit mode */
00804     lp->a.write_bcr (ioaddr, 20, 2);
00805 
00806     if (pcnet32_debug > 1)
00807         printk("%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n",
00808                dev->name, dev->irq,
00809                (u32) virt_to_bus(lp->tx_ring),
00810                (u32) virt_to_bus(lp->rx_ring),
00811                (u32) virt_to_bus(&lp->init_block));
00812     
00813     /* set/reset autoselect bit */
00814     val = lp->a.read_bcr (ioaddr, 2) & ~2;
00815     if (lp->options & PORT_ASEL)
00816         val |= 2;
00817     lp->a.write_bcr (ioaddr, 2, val);
00818     
00819     /* handle full duplex setting */
00820     if (lp->full_duplex) {
00821         val = lp->a.read_bcr (ioaddr, 9) & ~3;
00822         if (lp->options & PORT_FD) {
00823             val |= 1;
00824             if (lp->options == (PORT_FD | PORT_AUI))
00825                 val |= 2;
00826         }
00827         lp->a.write_bcr (ioaddr, 9, val);
00828     }
00829     
00830     /* NOOP ??? set/reset GPSI bit in test register */
00831     val = lp->a.read_csr (ioaddr, 124) & ~0x10;
00832     if ((lp->options & PORT_PORTSEL) == PORT_GPSI)
00833         val |= 0x10;
00834     lp->a.write_csr (ioaddr, 124, val);
00835     
00836     if (lp->mii & !(lp->options & PORT_ASEL)) {
00837         val = lp->a.read_bcr (ioaddr, 32) & ~0x38; /* disable Auto Negotiation, set 10Mpbs, HD */
00838         if (lp->options & PORT_FD)
00839             val |= 0x10;
00840         if (lp->options & PORT_100)
00841             val |= 0x08;
00842         lp->a.write_bcr (ioaddr, 32, val);
00843     }
00844 
00845 #ifdef DO_DXSUFLO 
00846     if (lp->dxsuflo) { /* Disable transmit stop on underflow */
00847         val = lp->a.read_csr (ioaddr, 3);
00848         val |= 0x40;
00849         lp->a.write_csr (ioaddr, 3, val);
00850     }
00851 #endif
00852     if (lp->ltint) { /* Enable TxDone-intr inhibitor */
00853         val = lp->a.read_csr (ioaddr, 5);
00854         val |= (1<<14);
00855         lp->a.write_csr (ioaddr, 5, val);
00856     }
00857     
00858     lp->init_block.mode = le16_to_cpu((lp->options & PORT_PORTSEL) << 7);
00859     lp->init_block.filter[0] = 0x00000000;
00860     lp->init_block.filter[1] = 0x00000000;
00861     if (pcnet32_init_ring(dev))
00862         return -ENOMEM;
00863     
00864     /* Re-initialize the PCNET32, and start it when done. */
00865     lp->a.write_csr (ioaddr, 1, virt_to_bus(&lp->init_block) &0xffff);
00866     lp->a.write_csr (ioaddr, 2, virt_to_bus(&lp->init_block) >> 16);
00867 
00868     lp->a.write_csr (ioaddr, 4, 0x0915);
00869     lp->a.write_csr (ioaddr, 0, 0x0001);
00870 
00871     dev->tbusy = 0;
00872     dev->interrupt = 0;
00873     dev->start = 1;
00874     i = 0;
00875     while (i++ < 100)
00876         if (lp->a.read_csr (ioaddr, 0) & 0x0100)
00877             break;
00878     /* 
00879      * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
00880      * reports that doing so triggers a bug in the '974.
00881      */
00882     lp->a.write_csr (ioaddr, 0, 0x0042);
00883 
00884     if (pcnet32_debug > 2)
00885         printk("%s: PCNET32 open after %d ticks, init block %#x csr0 %4.4x.\n",
00886                dev->name, i, (u32) virt_to_bus(&lp->init_block),
00887                lp->a.read_csr (ioaddr, 0));
00888 
00889     MOD_INC_USE_COUNT;
00890     
00891     return 0;   /* Always succeed */
00892 }
00893 
00894 /*
00895  * The LANCE has been halted for one reason or another (busmaster memory
00896  * arbitration error, Tx FIFO underflow, driver stopped it to reconfigure,
00897  * etc.).  Modern LANCE variants always reload their ring-buffer
00898  * configuration when restarted, so we must reinitialize our ring
00899  * context before restarting.  As part of this reinitialization,
00900  * find all packets still on the Tx ring and pretend that they had been
00901  * sent (in effect, drop the packets on the floor) - the higher-level
00902  * protocols will time out and retransmit.  It'd be better to shuffle
00903  * these skbs to a temp list and then actually re-Tx them after
00904  * restarting the chip, but I'm too lazy to do so right now.  dplatt@3do.com
00905  */
00906 
00907 static void 
00908 pcnet32_purge_tx_ring(struct device *dev)
00909 {
00910     struct pcnet32_private *lp = (struct pcnet32_private *)dev->priv;
00911     int i;
00912 
00913     for (i = 0; i < TX_RING_SIZE; i++) {
00914         if (lp->tx_skbuff[i]) {
00915             dev_kfree_skb(lp->tx_skbuff[i]);
00916             lp->tx_skbuff[i] = NULL;
00917         }
00918     }
00919 }
00920 
00921 
00922 /* Initialize the PCNET32 Rx and Tx rings. */
00923 static int
00924 pcnet32_init_ring(struct device *dev)
00925 {
00926     struct pcnet32_private *lp = (struct pcnet32_private *)dev->priv;
00927     int i;
00928 
00929     lp->tx_full = 0;
00930     lp->cur_rx = lp->cur_tx = 0;
00931     lp->dirty_rx = lp->dirty_tx = 0;
00932 
00933     for (i = 0; i < RX_RING_SIZE; i++) {
00934         if (lp->rx_skbuff[i] == NULL) {
00935             if (!(lp->rx_skbuff[i] = dev_alloc_skb (PKT_BUF_SZ))) {
00936                 /* there is not much, we can do at this point */
00937                 printk ("%s: pcnet32_init_ring dev_alloc_skb failed.\n",dev->name);
00938                 return -1;
00939             }
00940             skb_reserve (lp->rx_skbuff[i], 2);
00941         }
00942         lp->rx_ring[i].base = (u32)le32_to_cpu(virt_to_bus(lp->rx_skbuff[i]->tail));
00943         lp->rx_ring[i].buf_length = le16_to_cpu(-PKT_BUF_SZ);
00944         lp->rx_ring[i].status = le16_to_cpu(0x8000);
00945     }
00946     /* The Tx buffer address is filled in as needed, but we do need to clear
00947      the upper ownership bit. */
00948     for (i = 0; i < TX_RING_SIZE; i++) {
00949         lp->tx_ring[i].base = 0;
00950         lp->tx_ring[i].status = 0;
00951     }
00952 
00953     lp->init_block.tlen_rlen = le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS); 
00954     for (i = 0; i < 6; i++)
00955         lp->init_block.phys_addr[i] = dev->dev_addr[i];
00956     lp->init_block.rx_ring = (u32)le32_to_cpu(virt_to_bus(lp->rx_ring));
00957     lp->init_block.tx_ring = (u32)le32_to_cpu(virt_to_bus(lp->tx_ring));
00958     return 0;
00959 }
00960 
00961 static void
00962 pcnet32_restart(struct device *dev, unsigned int csr0_bits)
00963 {
00964     struct pcnet32_private *lp = (struct pcnet32_private *)dev->priv;
00965     unsigned long ioaddr = dev->base_addr;
00966     int i;
00967     
00968     pcnet32_purge_tx_ring(dev);
00969     if (pcnet32_init_ring(dev))
00970         return;
00971     
00972     /* ReInit Ring */
00973     lp->a.write_csr (ioaddr, 0, 1);
00974     i = 0;
00975     while (i++ < 100)
00976         if (lp->a.read_csr (ioaddr, 0) & 0x0100)
00977             break;
00978 
00979     lp->a.write_csr (ioaddr, 0, csr0_bits);
00980 }
00981 
00982 static int
00983 pcnet32_start_xmit(struct sk_buff *skb, struct device *dev)
00984 {
00985     struct pcnet32_private *lp = (struct pcnet32_private *)dev->priv;
00986     unsigned int ioaddr = dev->base_addr;
00987     u16 status;
00988     int entry;
00989     unsigned long flags;
00990 
00991     /* Transmitter timeout, serious problems. */
00992     if (dev->tbusy) {
00993         int tickssofar = jiffies - dev->trans_start;
00994         if (tickssofar < HZ/2)
00995             return 1;
00996         printk("%s: transmit timed out, status %4.4x, resetting.\n",
00997                dev->name, lp->a.read_csr (ioaddr, 0));
00998         lp->a.write_csr (ioaddr, 0, 0x0004);
00999         lp->stats.tx_errors++;
01000         if (pcnet32_debug > 2) {
01001             int i;
01002             printk(" Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
01003                    lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "",
01004                    lp->cur_rx);
01005             for (i = 0 ; i < RX_RING_SIZE; i++)
01006                 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
01007                        lp->rx_ring[i].base, -lp->rx_ring[i].buf_length,
01008                        lp->rx_ring[i].msg_length, (unsigned)lp->rx_ring[i].status);
01009             for (i = 0 ; i < TX_RING_SIZE; i++)
01010                 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
01011                        lp->tx_ring[i].base, -lp->tx_ring[i].length,
01012                        lp->tx_ring[i].misc, (unsigned)lp->tx_ring[i].status);
01013             printk("\n");
01014         }
01015         pcnet32_restart(dev, 0x0042);
01016 
01017         dev->tbusy = 0;
01018         dev->trans_start = jiffies;
01019         dev_kfree_skb(skb);
01020         return 0;
01021     }
01022 
01023     if (pcnet32_debug > 3) {
01024         printk("%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
01025                dev->name, lp->a.read_csr (ioaddr, 0));
01026     }
01027 
01028     /* Block a timer-based transmit from overlapping.  This could better be
01029        done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
01030     if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
01031         printk("%s: Transmitter access conflict.\n", dev->name);
01032         return 1;
01033     }
01034 
01035     spin_lock_irqsave(&lp->lock, flags);
01036 
01037     /* Default status -- will not enable Successful-TxDone
01038      * interrupt when that option is available to us.
01039      */
01040     status = 0x8300;
01041     if ((lp->ltint) &&
01042         ((lp->cur_tx - lp->dirty_tx == TX_RING_SIZE/2) ||
01043          (lp->cur_tx - lp->dirty_tx >= TX_RING_SIZE-2)))
01044     {
01045         /* Enable Successful-TxDone interrupt if we have
01046          * 1/2 of, or nearly all of, our ring buffer Tx'd
01047          * but not yet cleaned up.  Thus, most of the time,
01048          * we will not enable Successful-TxDone interrupts.
01049          */
01050         status = 0x9300;
01051     }
01052 
01053     /* Fill in a Tx ring entry */
01054 
01055     /* Mask to ring buffer boundary. */
01056     entry = lp->cur_tx & TX_RING_MOD_MASK;
01057 
01058     /* Caution: the write order is important here, set the base address
01059        with the "ownership" bits last. */
01060 
01061     lp->tx_ring[entry].length = le16_to_cpu(-skb->len);
01062 
01063     lp->tx_ring[entry].misc = 0x00000000;
01064 
01065     lp->tx_skbuff[entry] = skb;
01066     lp->tx_ring[entry].base = (u32)le32_to_cpu(virt_to_bus(skb->data));
01067 
01068     lp->tx_ring[entry].status = le16_to_cpu(status);
01069 
01070     lp->cur_tx++;
01071     lp->stats.tx_bytes += skb->len;
01072 
01073     /* Trigger an immediate send poll. */
01074     lp->a.write_csr (ioaddr, 0, 0x0048);
01075 
01076     dev->trans_start = jiffies;
01077 
01078     if (lp->tx_ring[(entry+1) & TX_RING_MOD_MASK].base == 0)
01079         clear_bit (0, (void *)&dev->tbusy);
01080     else
01081         lp->tx_full = 1;
01082     spin_unlock_irqrestore(&lp->lock, flags);
01083     return 0;
01084 }
01085 
01086 /* The PCNET32 interrupt handler. */
01087 static void
01088 pcnet32_interrupt(int irq, void *dev_id, struct pt_regs * regs)
01089 {
01090     struct device *dev = (struct device *)dev_id;
01091     struct pcnet32_private *lp;
01092     unsigned long ioaddr;
01093     u16 csr0,rap;
01094     int boguscnt =  max_interrupt_work;
01095     int must_restart;
01096 
01097     if (dev == NULL) {
01098         printk ("pcnet32_interrupt(): irq %d for unknown device.\n", irq);
01099         return;
01100     }
01101 
01102     ioaddr = dev->base_addr;
01103     lp = (struct pcnet32_private *)dev->priv;
01104 
01105     spin_lock(&lp->lock);
01106 
01107     if (dev->interrupt)
01108         printk("%s: Re-entering the interrupt handler.\n", dev->name);
01109 
01110     dev->interrupt = 1;
01111 
01112     rap = lp->a.read_rap(ioaddr);
01113     while ((csr0 = lp->a.read_csr (ioaddr, 0)) & 0x8600 && --boguscnt >= 0) {
01114         /* Acknowledge all of the current interrupt sources ASAP. */
01115         lp->a.write_csr (ioaddr, 0, csr0 & ~0x004f);
01116 
01117         must_restart = 0;
01118 
01119         if (pcnet32_debug > 5)
01120             printk("%s: interrupt  csr0=%#2.2x new csr=%#2.2x.\n",
01121                    dev->name, csr0, lp->a.read_csr (ioaddr, 0));
01122 
01123         if (csr0 & 0x0400)              /* Rx interrupt */
01124             pcnet32_rx(dev);
01125 
01126         if (csr0 & 0x0200) {            /* Tx-done interrupt */
01127             unsigned int dirty_tx = lp->dirty_tx;
01128 
01129             while (dirty_tx < lp->cur_tx) {
01130                 int entry = dirty_tx & TX_RING_MOD_MASK;
01131                 int status = (short)le16_to_cpu(lp->tx_ring[entry].status);
01132                         
01133                 if (status < 0)
01134                     break;              /* It still hasn't been Txed */
01135 
01136                 lp->tx_ring[entry].base = 0;
01137 
01138                 if (status & 0x4000) {
01139                     /* There was an major error, log it. */
01140                     int err_status = le32_to_cpu(lp->tx_ring[entry].misc);
01141                     lp->stats.tx_errors++;
01142                     if (err_status & 0x04000000) lp->stats.tx_aborted