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