root/drivers/net/tulip.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. dec21040_init
  2. tulip_probe
  3. tulip_probe1
  4. tulip_open
  5. tulip_init_ring
  6. tulip_start_xmit
  7. tulip_interrupt
  8. tulip_rx
  9. tulip_close
  10. tulip_get_stats
  11. set_multicast_list
  12. set_mac_address
  13. init_module
  14. cleanup_module

   1 /* tulip.c: A DEC 21040 ethernet driver for linux. */
   2 /*
   3    NOTICE: this version works with kernels 1.1.82 and later only!
   4         Written 1994,1995 by Donald Becker.
   5 
   6         This software may be used and distributed according to the terms
   7         of the GNU Public License, incorporated herein by reference.
   8 
   9         This driver is for the SMC EtherPower PCI ethernet adapter.
  10         It should work with most other DEC 21*40-based ethercards.
  11 
  12         The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
  13         Center of Excellence in Space Data and Information Sciences
  14            Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  15 */
  16 
  17 static const char *version = "tulip.c:v0.05 1/20/95 becker@cesdis.gsfc.nasa.gov\n";
  18 
  19 #ifdef MODULE
  20 #include <linux/module.h>
  21 #include <linux/version.h>
  22 #endif
  23 
  24 #include <linux/config.h>
  25 #include <linux/kernel.h>
  26 #include <linux/sched.h>
  27 #include <linux/string.h>
  28 #include <linux/ptrace.h>
  29 #include <linux/errno.h>
  30 #include <linux/ioport.h>
  31 #include <linux/malloc.h>
  32 #include <linux/interrupt.h>
  33 #include <linux/pci.h>
  34 #include <linux/bios32.h>
  35 #include <asm/bitops.h>
  36 #include <asm/io.h>
  37 #include <asm/dma.h>
  38 
  39 #include <linux/netdevice.h>
  40 #include <linux/etherdevice.h>
  41 #include <linux/skbuff.h>
  42 
  43 /* The total size is unusually large: The 21040 aligns each of its 16
  44    longword-wide registers on a quadword boundary. */
  45 #define TULIP_TOTAL_SIZE 0x80
  46 
  47 #ifdef HAVE_DEVLIST
  48 struct netdev_entry tulip_drv =
  49 {"Tulip", tulip_pci_probe, TULIP_TOTAL_SIZE, NULL};
  50 #endif
  51 
  52 #define TULIP_DEBUG 1
  53 #ifdef TULIP_DEBUG
  54 int tulip_debug = TULIP_DEBUG;
  55 #else
  56 int tulip_debug = 1;
  57 #endif
  58 
  59 /*
  60                                 Theory of Operation
  61 
  62 I. Board Compatibility
  63 
  64 This device driver is designed for the DECchip 21040 "Tulip", Digital's
  65 single-chip ethernet controller for PCI, as used on the SMC EtherPower
  66 ethernet adapter.
  67 
  68 II. Board-specific settings
  69 
  70 PCI bus devices are configured by the system at boot time, so no jumpers
  71 need to be set on the board.  The system BIOS should be set to assign the
  72 PCI INTA signal to an otherwise unused system IRQ line.  While it's
  73 physically possible to shared PCI interrupt lines, the kernel doesn't
  74 support it. 
  75 
  76 III. Driver operation
  77 
  78 IIIa. Ring buffers
  79 The Tulip can use either ring buffers or lists of Tx and Rx descriptors.
  80 The current driver uses a statically allocated Rx ring of descriptors and
  81 buffers, and a list of the Tx buffers.
  82 
  83 IIIC. Synchronization
  84 The driver runs as two independent, single-threaded flows of control.  One
  85 is the send-packet routine, which enforces single-threaded use by the
  86 dev->tbusy flag.  The other thread is the interrupt handler, which is single
  87 threaded by the hardware and other software.
  88 
  89 The send packet thread has partial control over the Tx ring and 'dev->tbusy'
  90 flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
  91 queue slot is empty, it clears the tbusy flag when finished otherwise it sets
  92 the 'tp->tx_full' flag.
  93 
  94 The interrupt handler has exclusive control over the Rx ring and records stats
  95 from the Tx ring.  (The Tx-done interrupt can't be selectively turned off, so
  96 we can't avoid the interrupt overhead by having the Tx routine reap the Tx
  97 stats.)  After reaping the stats, it marks the queue entry as empty by setting
  98 the 'base' to zero.      Iff the 'tp->tx_full' flag is set, it clears both the
  99 tx_full and tbusy flags.
 100 
 101 IV. Notes
 102 
 103 Thanks to Duke Kamstra of SMC for providing an EtherPower board.
 104 
 105 The DEC databook doesn't document which Rx filter settings accept broadcast
 106 packets.  Nor does it document how to configure the part to configure the
 107 serial subsystem for normal (vs. loopback) operation or how to have it
 108 autoswitch between internal 10baseT, SIA and AUI transceivers.
 109 
 110 The databook claims that CSR13, CSR14, and CSR15 should each be the last
 111 register of the set CSR12-15 written.   Hmmm, now how is that possible?
 112 */
 113 
 114 #define DEC_VENDOR_ID   0x1011          /* Hex 'D' :-> */
 115 #define DEC_21040_ID    0x0002          /* Change for 21140. */
 116 
 117 /* Keep the ring sizes a power of two for efficiency. */
 118 #define TX_RING_SIZE    4
 119 #define RX_RING_SIZE    4
 120 #define PKT_BUF_SZ              1536                    /* Size of each temporary Rx buffer.*/
 121 
 122 /* Offsets to the Command and Status Registers, "CSRs".  All accesses
 123    must be longword instructions and quadword aligned. */
 124 enum tulip_offsets {
 125         CSR0=0,    CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
 126         CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
 127         CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78 };
 128 
 129 /* The Tulip Rx and Tx buffer descriptors. */
 130 struct tulip_rx_desc {
 131         int status;
 132         int length;
 133         char *buffer1, *buffer2;                        /* We use only buffer 1.  */
 134 };
 135 
 136 struct tulip_tx_desc {
 137         int status;
 138         int length;
 139         char *buffer1, *buffer2;                        /* We use only buffer 1.  */
 140 };
 141 
 142 struct tulip_private {
 143         char devname[8];                        /* Used only for kernel debugging. */
 144         struct tulip_rx_desc rx_ring[RX_RING_SIZE];
 145         struct tulip_tx_desc tx_ring[TX_RING_SIZE];
 146         /* The saved address of a sent-in-place packet/buffer, for skfree(). */
 147         struct sk_buff* tx_skbuff[TX_RING_SIZE];
 148         long rx_buffs;                          /* Address of temporary Rx buffers. */
 149         struct enet_statistics stats;
 150         int setup_frame[48];            /* Pseudo-Tx frame to init address table. */
 151         unsigned int cur_rx, cur_tx;            /* The next free ring entry */
 152         unsigned int dirty_rx, dirty_tx;        /* The ring entries to be free()ed. */
 153         unsigned int tx_full:1;
 154         int pad0, pad1;                                         /* Used for 8-byte alignment */
 155 };
 156 
 157 static void tulip_probe1(int ioaddr, int irq);
 158 static int tulip_open(struct device *dev);
 159 static void tulip_init_ring(struct device *dev);
 160 static int tulip_start_xmit(struct sk_buff *skb, struct device *dev);
 161 static int tulip_rx(struct device *dev);
 162 static void tulip_interrupt(int irq, struct pt_regs *regs);
 163 static int tulip_close(struct device *dev);
 164 static struct enet_statistics *tulip_get_stats(struct device *dev);
 165 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 166 static int set_mac_address(struct device *dev, void *addr);
 167 
 168 
 169 
 170 #ifndef MODULE
 171 /* This 21040 probe is unlike most other board probes.  We can use memory
 172    efficiently by allocating a large contiguous region and dividing it
 173    ourselves.  This is done by having the initialization occur before
 174    the 'kmalloc()' memory management system is started. */
 175 
 176 int dec21040_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 177 {
 178 
 179     if (pcibios_present()) {
 180             int pci_index;
 181                 for (pci_index = 0; pci_index < 8; pci_index++) {
 182                         unsigned char pci_bus, pci_device_fn, pci_irq_line;
 183                         unsigned long pci_ioaddr;
 184                 
 185                         if (pcibios_find_device (DEC_VENDOR_ID, DEC_21040_ID, pci_index,
 186                                                                          &pci_bus, &pci_device_fn) != 0)
 187                                 break;
 188                         pcibios_read_config_byte(pci_bus, pci_device_fn,
 189                                                                          PCI_INTERRUPT_LINE, &pci_irq_line);
 190                         pcibios_read_config_dword(pci_bus, pci_device_fn,
 191                                                                           PCI_BASE_ADDRESS_0, &pci_ioaddr);
 192                         /* Remove I/O space marker in bit 0. */
 193                         pci_ioaddr &= ~3;
 194                         if (tulip_debug > 2)
 195                                 printk("Found DEC PCI Tulip at I/O %#lx, IRQ %d.\n",
 196                                            pci_ioaddr, pci_irq_line);
 197                         tulip_probe1(pci_ioaddr, pci_irq_line);
 198                 }
 199         }
 200 
 201         return 0;
 202 }
 203 #endif
 204 #ifdef MODULE
 205 static int tulip_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 206 {
 207         printk("tulip: This driver does not yet install properly from module!\n");
 208         return -1;
 209 }
 210 #endif
 211 
 212 static void tulip_probe1(int ioaddr, int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 213 {
 214         static int did_version = 0;                     /* Already printed version info. */
 215         struct device *dev;
 216         struct tulip_private *tp;
 217         int i;
 218 
 219         if (tulip_debug > 0  &&  did_version++ == 0)
 220                 printk(version);
 221 
 222         dev = init_etherdev(0, 0);
 223 
 224         printk("%s: DEC 21040 Tulip at %#3x,", dev->name, ioaddr);
 225 
 226         /* Stop the chip's Tx and Rx processes. */
 227         outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
 228         /* Clear the missed-packet counter. */
 229         inl(ioaddr + CSR8) & 0xffff;
 230 
 231         /* The station address ROM is read byte serially.  The register must
 232            be polled, waiting for the value to be read bit serially from the
 233            EEPROM.
 234            */
 235         outl(0, ioaddr + CSR9);         /* Reset the pointer with a dummy write. */
 236         for (i = 0; i < 6; i++) {
 237                 int value, boguscnt = 100000;
 238                 do
 239                         value = inl(ioaddr + CSR9);
 240                 while (value < 0  && --boguscnt > 0);
 241                 printk(" %2.2x", dev->dev_addr[i] = value);
 242         }
 243         printk(", IRQ %d\n", irq);
 244 
 245         /* We do a request_region() only to register /proc/ioports info. */
 246         request_region(ioaddr, TULIP_TOTAL_SIZE, "DEC Tulip Ethernet");
 247 
 248         dev->base_addr = ioaddr;
 249         dev->irq = irq;
 250 
 251         /* Make certain the data structures are quadword aligned. */
 252         tp = kmalloc(sizeof(*tp), GFP_KERNEL | GFP_DMA);
 253         dev->priv = tp;
 254         tp->rx_buffs = kmalloc(PKT_BUF_SZ*RX_RING_SIZE, GFP_KERNEL | GFP_DMA);
 255 
 256         /* The Tulip-specific entries in the device structure. */
 257         dev->open = &tulip_open;
 258         dev->hard_start_xmit = &tulip_start_xmit;
 259         dev->stop = &tulip_close;
 260         dev->get_stats = &tulip_get_stats;
 261 #ifdef HAVE_MULTICAST
 262         dev->set_multicast_list = &set_multicast_list;
 263 #endif
 264 #ifdef HAVE_SET_MAC_ADDR
 265         dev->set_mac_address = &set_mac_address;
 266 #endif
 267 
 268         return;
 269 }
 270 
 271 
 272 static int
 273 tulip_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 274 {
 275         struct tulip_private *tp = (struct tulip_private *)dev->priv;
 276         int ioaddr = dev->base_addr;
 277 
 278         /* Reset the chip, holding bit 0 set at least 10 PCI cycles. */
 279         outl(0xfff80001, ioaddr + CSR0);
 280         SLOW_DOWN_IO;
 281         /* Deassert reset.  Set 8 longword cache alignment, 8 longword burst.
 282            Cache alignment bits 15:14        Burst length 13:8
 283         0000    No alignment  0x00000000 unlimited              0800 8 longwords
 284                 4000    8  longwords            0100 1 longword         1000 16 longwords
 285                 8000    16 longwords            0200 2 longwords        2000 32 longwords
 286                 C000    32  longwords           0400 4 longwords
 287            Wait the specified 50 PCI cycles after a reset by initializing
 288            Tx and Rx queues and the address filter list. */
 289         outl(0xfff84800, ioaddr + CSR0);
 290 
 291         if (irq2dev_map[dev->irq] != NULL
 292                 || (irq2dev_map[dev->irq] = dev) == NULL
 293                 || dev->irq == 0
 294                 || request_irq(dev->irq, &tulip_interrupt, 0, "DEC 21040 Tulip")) {
 295                 return -EAGAIN;
 296         }
 297 
 298         if (tulip_debug > 1)
 299                 printk("%s: tulip_open() irq %d.\n", dev->name, dev->irq);
 300 
 301         tulip_init_ring(dev);
 302 
 303         /* Fill the whole address filter table with our physical address. */
 304         { 
 305                 unsigned short *eaddrs = (unsigned short *)dev->dev_addr;
 306                 int *setup_frm = tp->setup_frame, i;
 307 
 308                 /* You must add the broadcast address when doing perfect filtering! */
 309                 *setup_frm++ = 0xffff;
 310                 *setup_frm++ = 0xffff;
 311                 *setup_frm++ = 0xffff;
 312                 /* Fill the rest of the accept table with our physical address. */
 313                 for (i = 1; i < 16; i++) {
 314                         *setup_frm++ = eaddrs[0];
 315                         *setup_frm++ = eaddrs[1];
 316                         *setup_frm++ = eaddrs[2];
 317                 }
 318                 /* Put the setup frame on the Tx list. */
 319                 tp->tx_ring[0].length = 0x08000000 | 192;
 320                 tp->tx_ring[0].buffer1 = (char *)tp->setup_frame;
 321                 tp->tx_ring[0].buffer2 = 0;
 322                 tp->tx_ring[0].status = 0x80000000;
 323 
 324                 tp->cur_tx++, tp->dirty_tx++;
 325         }
 326 
 327         outl((int)tp->rx_ring, ioaddr + CSR3);
 328         outl((int)tp->tx_ring, ioaddr + CSR4);
 329 
 330         /* Turn on the xcvr interface. */
 331         outl(0x00000000, ioaddr + CSR13);
 332         outl(0x00000004, ioaddr + CSR13);
 333 
 334         /* Start the chip's Tx and Rx processes. */
 335         outl(0xfffe2002, ioaddr + CSR6);
 336 
 337         /* Trigger an immediate transmit demand to process the setup frame. */
 338         outl(0, ioaddr + CSR1);
 339 
 340         dev->tbusy = 0;
 341         dev->interrupt = 0;
 342         dev->start = 1;
 343 
 344         /* Enable interrupts by setting the interrupt mask. */
 345         outl(0xFFFFFFFF, ioaddr + CSR7);
 346 
 347         if (tulip_debug > 2) {
 348                 printk("%s: Done tulip_open(), CSR0 %8.8x, CSR13 %8.8x.\n",
 349                            dev->name, inl(ioaddr + CSR0), inl(ioaddr + CSR13));
 350         }
 351 #ifdef MODULE
 352         MOD_INC_USE_COUNT;
 353 #endif
 354         return 0;
 355 }
 356 
 357 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
 358 static void
 359 tulip_init_ring(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 360 {
 361         struct tulip_private *tp = (struct tulip_private *)dev->priv;
 362         int i;
 363 
 364         tp->tx_full = 0;
 365         tp->cur_rx = tp->cur_tx = 0;
 366         tp->dirty_rx = tp->dirty_tx = 0;
 367 
 368         for (i = 0; i < RX_RING_SIZE; i++) {
 369                 tp->rx_ring[i].status = 0x80000000;     /* Owned by Tulip chip */
 370                 tp->rx_ring[i].length = PKT_BUF_SZ;
 371                 tp->rx_ring[i].buffer1 = (char *)(tp->rx_buffs + i*PKT_BUF_SZ);
 372                 tp->rx_ring[i].buffer2 = (char *)&tp->rx_ring[i+1];
 373         }
 374         /* Mark the last entry as wrapping the ring. */ 
 375         tp->rx_ring[i-1].length = PKT_BUF_SZ | 0x02000000;
 376         tp->rx_ring[i-1].buffer2 = (char *)&tp->rx_ring[0];
 377 
 378         /* The Tx buffer descriptor is filled in as needed, but we
 379            do need to clear the ownership bit. */
 380         for (i = 0; i < TX_RING_SIZE; i++) {
 381                 tp->tx_ring[i].status = 0x00000000;
 382         }
 383 }
 384 
 385 static int
 386 tulip_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 387 {
 388         struct tulip_private *tp = (struct tulip_private *)dev->priv;
 389         int ioaddr = dev->base_addr;
 390         int entry;
 391 
 392         /* Transmitter timeout, serious problems. */
 393         if (dev->tbusy) {
 394                 int tickssofar = jiffies - dev->trans_start;
 395                 int i;
 396                 if (tickssofar < 20)
 397                         return 1;
 398                 printk("%s: transmit timed out, status %8.8x, SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
 399                            dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12),
 400                            inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15));
 401                 printk("  Rx ring %8.8x: ", (int)tp->rx_ring);
 402                 for (i = 0; i < RX_RING_SIZE; i++)
 403                         printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
 404                 printk("\n  Tx ring %8.8x: ", (int)tp->tx_ring);
 405                 for (i = 0; i < TX_RING_SIZE; i++)
 406                         printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
 407                 printk("\n");
 408 
 409                 tp->stats.tx_errors++;
 410                 /* We should reinitialize the hardware here. */
 411                 dev->tbusy=0;
 412                 dev->trans_start = jiffies;
 413                 return 0;
 414         }
 415 
 416         if (skb == NULL || skb->len <= 0) {
 417                 printk("%s: Obsolete driver layer request made: skbuff==NULL.\n",
 418                            dev->name);
 419                 dev_tint(dev);
 420                 return 0;
 421         }
 422 
 423         /* Block a timer-based transmit from overlapping.  This could better be
 424            done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
 425            If this ever occurs the queue layer is doing something evil! */
 426         if (set_bit(0, (void*)&dev->tbusy) != 0) {
 427                 printk("%s: Transmitter access conflict.\n", dev->name);
 428                 return 1;
 429         }
 430 
 431         /* Caution: the write order is important here, set the base address
 432            with the "ownership" bits last. */
 433 
 434         /* Calculate the next Tx descriptor entry. */
 435         entry = tp->cur_tx % TX_RING_SIZE;
 436 
 437         tp->tx_full = 1;
 438         tp->tx_skbuff[entry] = skb;
 439         tp->tx_ring[entry].length = skb->len |
 440                 (entry == TX_RING_SIZE-1 ? 0xe2000000 : 0xe0000000);
 441         tp->tx_ring[entry].buffer1 = skb->data;
 442         tp->tx_ring[entry].buffer2 = 0;
 443         tp->tx_ring[entry].status = 0x80000000; /* Pass ownership to the chip. */
 444 
 445         tp->cur_tx++;
 446 
 447         /* Trigger an immediate transmit demand. */
 448         outl(0, ioaddr + CSR1);
 449 
 450         dev->trans_start = jiffies;
 451 
 452         return 0;
 453 }
 454 
 455 /* The interrupt handler does all of the Rx thread work and cleans up
 456    after the Tx thread. */
 457 static void tulip_interrupt(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 458 {
 459         struct device *dev = (struct device *)(irq2dev_map[irq]);
 460         struct tulip_private *lp;
 461         int csr5, ioaddr, boguscnt=10;
 462 
 463         if (dev == NULL) {
 464                 printk ("tulip_interrupt(): irq %d for unknown device.\n", irq);
 465                 return;
 466         }
 467 
 468         ioaddr = dev->base_addr;
 469         lp = (struct tulip_private *)dev->priv;
 470         if (dev->interrupt)
 471                 printk("%s: Re-entering the interrupt handler.\n", dev->name);
 472 
 473         dev->interrupt = 1;
 474 
 475         do {
 476                 csr5 = inl(ioaddr + CSR5);
 477                 /* Acknowledge all of the current interrupt sources ASAP. */
 478                 outl(csr5 & 0x0001ffff, ioaddr + CSR5);
 479 
 480                 if (tulip_debug > 4)
 481                         printk("%s: interrupt  csr5=%#8.8x new csr5=%#8.8x.\n",
 482                                    dev->name, csr5, inl(dev->base_addr + CSR5));
 483 
 484                 if ((csr5 & 0x00018000) == 0)
 485                         break;
 486 
 487                 if (csr5 & 0x0040)                      /* Rx interrupt */
 488                         tulip_rx(dev);
 489 
 490                 if (csr5 & 0x0001) {            /* Tx-done interrupt */
 491                         int dirty_tx = lp->dirty_tx;
 492 
 493                         while (dirty_tx < lp->cur_tx) {
 494                                 int entry = dirty_tx % TX_RING_SIZE;
 495                                 int status = lp->tx_ring[entry].status;
 496 
 497                                 if (status < 0)
 498                                         break;                  /* It still hasn't been Txed */
 499 
 500                                 if (status & 0x8000) {
 501                                         /* There was an major error, log it. */
 502                                         lp->stats.tx_errors++;
 503                                         if (status & 0x4104) lp->stats.tx_aborted_errors++;
 504                                         if (status & 0x0C00) lp->stats.tx_carrier_errors++;
 505                                         if (status & 0x0200) lp->stats.tx_window_errors++;
 506                                         if (status & 0x0002) lp->stats.tx_fifo_errors++;
 507                                         if (status & 0x0080) lp->stats.tx_heartbeat_errors++;
 508 #ifdef ETHER_STATS
 509                                         if (status & 0x0100) lp->stats.collisions16++;
 510 #endif
 511                                 } else {
 512 #ifdef ETHER_STATS
 513                                         if (status & 0x0001) lp->stats.tx_deferred++;
 514 #endif
 515                                         lp->stats.collisions += (status >> 3) & 15;
 516                                         lp->stats.tx_packets++;
 517                                 }
 518 
 519                                 /* Free the original skb. */
 520                                 dev_kfree_skb(lp->tx_skbuff[entry], FREE_WRITE);
 521                                 dirty_tx++;
 522                         }
 523 
 524 #ifndef final_version
 525                         if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
 526                                 printk("out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
 527                                            dirty_tx, lp->cur_tx, lp->tx_full);
 528                                 dirty_tx += TX_RING_SIZE;
 529                         }
 530 #endif
 531 
 532                         if (lp->tx_full && dev->tbusy
 533                                 && dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
 534                                 /* The ring is no longer full, clear tbusy. */
 535                                 lp->tx_full = 0;
 536                                 dev->tbusy = 0;
 537                                 mark_bh(NET_BH);
 538                         }
 539 
 540                         lp->dirty_tx = dirty_tx;
 541                 }
 542 
 543                 /* Log errors. */
 544                 if (csr5 & 0x8000) {    /* Abnormal error summary bit. */
 545                         if (csr5 & 0x0008) lp->stats.tx_errors++; /* Tx babble. */
 546                         if (csr5 & 0x0100) {            /* Missed a Rx frame. */
 547                                 lp->stats.rx_errors++;
 548                                 lp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
 549                         }
 550                         if (csr5 & 0x0800) {
 551                                 printk("%s: Something Wicked happened! %8.8x.\n",
 552                                            dev->name, csr5);
 553                                 /* Hmmmmm, it's not clear what to do here. */
 554                         }
 555                 }
 556                 if (--boguscnt < 0) {
 557                         printk("%s: Too much work at interrupt, csr5=0x%8.8x.\n",
 558                                    dev->name, csr5);
 559                         /* Clear all interrupt sources. */
 560                         outl(0x0001ffff, ioaddr + CSR5);
 561                         break;
 562                 }
 563         } while (1);
 564 
 565         if (tulip_debug > 3)
 566                 printk("%s: exiting interrupt, csr5=%#4.4x.\n",
 567                            dev->name, inl(ioaddr + CSR5));
 568 
 569         /* Special code for testing *only*. */
 570         {
 571                 static int stopit = 10;
 572                 if (dev->start == 0  &&  --stopit < 0) {
 573                         printk("%s: Emergency stop, looping startup interrupt.\n",
 574                                    dev->name);
 575                         free_irq(irq);
 576                 }
 577         }
 578 
 579         dev->interrupt = 0;
 580         return;
 581 }
 582 
 583 static int
 584 tulip_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 585 {
 586         struct tulip_private *lp = (struct tulip_private *)dev->priv;
 587         int entry = lp->cur_rx % RX_RING_SIZE;
 588         int i;
 589                 
 590         if (tulip_debug > 4)
 591                 printk(" In tulip_rx().\n");
 592         /* If we own the next entry, it's a new packet. Send it up. */
 593         while (lp->rx_ring[entry].status >= 0) {
 594                 int status = lp->rx_ring[entry].status;
 595 
 596                 if (tulip_debug > 4)
 597                         printk("  tulip_rx() status was %8.8x.\n", status);
 598                 if ((status & 0x0300) != 0x0300) {
 599                         printk("%s: Ethernet frame spanned multiple buffers, status %8.8x!\n",
 600                                    dev->name, status);
 601                 } else if (status & 0x8000) {
 602                         /* There was a fatal error. */
 603                         lp->stats.rx_errors++; /* end of a packet.*/
 604                         if (status & 0x0890) lp->stats.rx_length_errors++;
 605                         if (status & 0x0004) lp->stats.rx_frame_errors++;
 606                         if (status & 0x0002) lp->stats.rx_crc_errors++;
 607                         if (status & 0x0001) lp->stats.rx_fifo_errors++;
 608                 } else {
 609                         /* Malloc up new buffer, compatible with net-2e. */
 610                         short pkt_len = lp->rx_ring[entry].status >> 16;
 611                         struct sk_buff *skb;
 612 
 613                         skb = dev_alloc_skb(pkt_len+2);
 614                         if (skb == NULL) {
 615                                 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
 616                                 /* Check that at least two ring entries are free.
 617                                    If not, free one and mark stats->rx_dropped++. */
 618                                 for (i=0; i < RX_RING_SIZE; i++)
 619                                         if (lp->rx_ring[(entry+i) % RX_RING_SIZE].status < 0)
 620                                                 break;
 621 
 622                                 if (i > RX_RING_SIZE -2) {
 623                                         lp->stats.rx_dropped++;
 624                                         lp->rx_ring[entry].status = 0x80000000;
 625                                         lp->cur_rx++;
 626                                 }
 627                                 break;
 628                         }
 629                         skb->dev = dev;
 630                         skb_reserve(skb,2);     /* 16 byte align the data fields */
 631                         memcpy(skb_put(skb,pkt_len), lp->rx_ring[entry].buffer1, pkt_len);
 632                         skb->protocol=eth_type_trans(skb,dev);
 633                         netif_rx(skb);
 634                         lp->stats.rx_packets++;
 635                 }
 636 
 637                 lp->rx_ring[entry].status = 0x80000000;
 638                 entry = (++lp->cur_rx) % RX_RING_SIZE;
 639         }
 640 
 641         return 0;
 642 }
 643 
 644 static int
 645 tulip_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 646 {
 647         int ioaddr = dev->base_addr;
 648         struct tulip_private *tp = (struct tulip_private *)dev->priv;
 649 
 650         dev->start = 0;
 651         dev->tbusy = 1;
 652 
 653         if (tulip_debug > 1)
 654                 printk("%s: Shutting down ethercard, status was %2.2x.\n",
 655                            dev->name, inl(ioaddr + CSR5));
 656 
 657         /* Disable interrupts by clearing the interrupt mask. */
 658         outl(0x00000000, ioaddr + CSR7);
 659         /* Stop the chip's Tx and Rx processes. */
 660         outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
 661 
 662         tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
 663 
 664         free_irq(dev->irq);
 665         irq2dev_map[dev->irq] = 0;
 666 
 667 #ifdef MODULE
 668         MOD_DEC_USE_COUNT;
 669 #endif
 670         return 0;
 671 }
 672 
 673 static struct enet_statistics *
 674 tulip_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 675 {
 676         struct tulip_private *tp = (struct tulip_private *)dev->priv;
 677         short ioaddr = dev->base_addr;
 678 
 679         tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
 680 
 681         return &tp->stats;
 682 }
 683 
 684 /* Set or clear the multicast filter for this adaptor.
 685    num_addrs == -1              Promiscuous mode, receive all packets
 686    num_addrs == 0               Normal mode, clear multicast list
 687    num_addrs > 0                Multicast mode, receive normal and MC packets, and do
 688                                                 best-effort filtering.
 689  */
 690 static void
 691 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 692 {
 693         short ioaddr = dev->base_addr;
 694         int csr6 = inl(ioaddr + CSR6) & ~0x00D5;
 695 
 696         if (num_addrs > 15 || num_addrs == -2) {
 697                 /* Too many to filter perfectly -- accept all multicasts. */
 698                 outl(csr6 | 0x0080, ioaddr + CSR6);
 699         } else if (num_addrs < 0) {                     /* Set promiscuous. */
 700                 outl(csr6 | 0x00C0, ioaddr + CSR6);
 701                 /* Log any net taps. */
 702                 printk("%s: Promiscuous mode enabled.\n", dev->name);
 703         } else {
 704                 struct tulip_private *tp = (struct tulip_private *)dev->priv;
 705                 int *setup_frm = tp->setup_frame;
 706                 unsigned short *eaddrs = addrs;
 707                 int i;
 708 
 709                 /* We have <= 15 addresses that we can use the wonderful
 710                    16 address perfect filtering of the Tulip.  Note that only
 711                    the low shortword of setup_frame[] is valid. */
 712                 outl(csr6 | 0x0000, ioaddr + CSR6);
 713                 for(i = 0; i < num_addrs; i++) {
 714                         *setup_frm++ = *eaddrs++;
 715                         *setup_frm++ = *eaddrs++;
 716                         *setup_frm++ = *eaddrs++;
 717                 }
 718                 /* Fill the rest of the table with our physical address. */
 719                 eaddrs = (unsigned short *)dev->dev_addr;
 720                 do {
 721                         *setup_frm++ = eaddrs[0];
 722                         *setup_frm++ = eaddrs[1];
 723                         *setup_frm++ = eaddrs[2];
 724                 } while (++i < 16);
 725 
 726                 /* Now add this frame to the Tx list. */
 727         }
 728 }
 729 
 730 static int
 731 set_mac_address(struct device *dev, void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 732 {
 733         int i;
 734         if (dev->start)
 735                 return -EBUSY;
 736         printk("%s: Setting MAC address to ", dev->name);
 737         for (i = 0; i < 6; i++)
 738                 printk(" %2.2x", dev->dev_addr[i] = ((unsigned char *)addr)[i]);
 739         printk(".\n");
 740         return 0;
 741 }
 742 
 743 #ifdef MODULE
 744 char kernel_version[] = UTS_RELEASE;
 745 static char devicename[9] = { 0, };
 746 static struct device dev_tulip = {
 747         devicename, /* device name is inserted by linux/drivers/net/net_init.c */
 748         0, 0, 0, 0,
 749         0, 0,
 750         0, 0, 0, NULL, tulip_probe
 751 };
 752 
 753 int io = 0;
 754 int irq = 0;
 755 
 756 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 757 {
 758         printk("tulip: Sorry, modularization is not completed\n");
 759         return -EIO;
 760 #if 0
 761         if (io == 0)
 762           printk("tulip: You should not use auto-probing with insmod!\n");
 763         dev_tulip.base_addr = io;
 764         dev_tulip.irq       = irq;
 765         if (register_netdev(&dev_tulip) != 0) {
 766                 printk("tulip: register_netdev() returned non-zero.\n");
 767                 return -EIO;
 768         }
 769         return 0;
 770 #endif
 771 }
 772 
 773 void
 774 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 775 {
 776         if (MOD_IN_USE)
 777                 printk("tulip: device busy, remove delayed\n");
 778         else
 779         {
 780                 unregister_netdev(&dev_tulip);
 781         }
 782 }
 783 #endif /* MODULE */
 784 
 785 /*
 786  * Local variables:
 787  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c tulip.c"
 788  *  c-indent-level: 4
 789  *  tab-width: 4
 790  * End:
 791  */

/* [previous][next][first][last][top][bottom][index][help] */