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

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