* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-0.99 / drivers / net / 8390.c
blob9c896cc59941b684e6613a9cb4f6cf05957e2583
1 /* 8390.c: A general NS8390 ethernet driver core for linux. */
2 /*
3 Written 1992,1993 by Donald Becker.
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency. This software may be used and
7 distributed according to the terms of the GNU Public License,
8 incorporated herein by reference.
10 This is the chip-specific code for many 8390-based ethernet adaptors.
12 The Author may be reached as becker@super.org or
13 C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
16 static char *version =
17 "8390.c:v0.99-13f 10/18/93 Donald Becker (becker@super.org)\n";
18 #include <linux/config.h>
21 Braindamage remaining:
23 Ethernet devices should use a chr_drv device interface, with ioctl()s to
24 configure the card, bring the interface up or down, allow access to
25 statistics, and maybe read() and write() access to raw packets.
26 This won't be done until after Linux 1.00.
28 Sources:
29 The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
30 The NE* programming info came from the Crynwr packet driver, and figuring
31 out that the those boards are similar to the NatSemi evaluation board
32 described in AN-729. Thanks NS, no thanks to Novell/Eagle.
35 #include <linux/config.h>
36 #include <linux/kernel.h>
37 #include <linux/sched.h>
38 #include <linux/fs.h>
39 #include <linux/types.h>
40 #include <linux/ptrace.h>
41 #include <linux/string.h>
42 #include <asm/system.h>
43 #include <asm/segment.h>
44 #include <asm/bitops.h>
45 #include <asm/io.h>
46 #include <errno.h>
47 #include <linux/fcntl.h>
48 #include <linux/in.h>
49 #include <linux/interrupt.h>
51 #include "dev.h"
52 #include "eth.h"
53 #include "ip.h"
54 #include "protocol.h"
55 #include "tcp.h"
56 #include "skbuff.h"
57 #include "sock.h"
58 #include "arp.h"
60 #include "8390.h"
62 #ifndef HAVE_ALLOC_SKB
63 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
64 #define kfree_skbmem(addr, size) kfree_s(addr,size)
65 #endif
67 #define ei_reset_8390 (ei_local->reset_8390)
68 #define ei_block_output (ei_local->block_output)
69 #define ei_block_input (ei_local->block_input)
71 /* use 0 for production, 1 for verification, >2 for debug */
72 #ifdef EI_DEBUG
73 int ei_debug = EI_DEBUG;
74 #else
75 int ei_debug = 1;
76 #endif
78 /* Max number of packets received at one Intr. */
79 /*static int high_water_mark = 0;*/
81 /* Index to functions. */
82 /* Put in the device structure. */
83 int ei_open(struct device *dev);
84 /* Dispatch from interrupts. */
85 void ei_interrupt(int reg_ptr);
86 static void ei_tx_intr(struct device *dev);
87 static void ei_receive(struct device *dev);
88 static void ei_rx_overrun(struct device *dev);
90 /* Routines generic to NS8390-based boards. */
91 void NS8390_init(struct device *dev, int startp);
92 static void NS8390_trigger_send(struct device *dev, unsigned int length,
93 int start_page);
94 #ifdef HAVE_MULTICAST
95 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
96 #endif
98 struct sigaction ei_sigaction = { ei_interrupt, 0, 0, NULL, };
100 /* Open/initialize the board. This routine goes all-out, setting everything
101 up anew at each open, even though many of these registers should only
102 need to be set once at boot.
104 int ei_open(struct device *dev)
106 struct ei_device *ei_local = (struct ei_device *) dev->priv;
108 if ( ! ei_local) {
109 printk("%s: Opening a non-existent physical device\n", dev->name);
110 return 1; /* ENXIO would be more accurate. */
113 irq2dev_map[dev->irq] = dev;
114 NS8390_init(dev, 1);
115 ei_local->tx1 = ei_local->tx2 = 0;
116 /* The old local flags... */
117 ei_local->txing = 0;
118 /* ... are now global. */
119 dev->tbusy = 0;
120 dev->interrupt = 0;
121 dev->start = 1;
122 ei_local->irqlock = 0;
123 return 0;
126 static int ei_start_xmit(struct sk_buff *skb, struct device *dev)
128 int e8390_base = dev->base_addr;
129 struct ei_device *ei_local = (struct ei_device *) dev->priv;
130 int length, send_length;
131 int tmp_tbusy; /* we must lock dev_tint in dev.c with dev->t_busy =1 */
132 /* because on a slow pc a quasi endless loop can appear */
134 if (dev->tbusy) { /* Do timeouts, just like the 8003 driver. */
135 int txsr = inb(e8390_base+EN0_TSR), isr;
136 int tickssofar = jiffies - dev->trans_start;
137 if (tickssofar < 5 || (tickssofar < 15 && ! (txsr & ENTSR_PTX))) {
138 return 1;
140 isr = inb(e8390_base+EN0_ISR);
141 printk("%s: transmit timed out, TX status %#2x, ISR %#2x.\n",
142 dev->name, txsr, isr);
143 /* It's possible to check for an IRQ conflict here.
144 I may have to do that someday. */
145 if (isr)
146 printk("%s: Possible IRQ conflict on IRQ%d?", dev->name, dev->irq);
147 else
148 printk("%s: Possible network cable problem?\n", dev->name);
149 /* It futile, but try to restart it anyway. */
150 ei_reset_8390(dev);
151 NS8390_init(dev, 1);
152 printk("\n");
155 /* This is new: it means some higher layer thinks we've missed an
156 tx-done interrupt. Caution: dev_tint() handles the cli()/sti()
157 itself. */
158 if (skb == NULL) {
159 dev_tint(dev);
160 return 0;
162 /* Fill in the ethernet header. */
163 if (!skb->arp && dev->rebuild_header(skb->data, dev)) {
164 skb->dev = dev;
165 arp_queue (skb);
166 return 0;
168 skb->arp=1;
170 if (skb->len <= 0)
171 return 0;
172 length = skb->len;
173 send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
174 /* Turn off interrupts so that we can put the packet out safely. */
175 cli();
176 if (dev->interrupt || ei_local->irqlock) {
177 /* We should never get here during an interrupt after 0.99.4. */
178 sti();
179 if (ei_debug > 2)
180 printk("%s: Attempt to reenter critical zone%s.\n",
181 dev->name, ei_local->irqlock ? " during interrupt" : "");
182 return 1;
184 /* Mask interrupts from the ethercard. */
185 outb(0x00, e8390_base + EN0_IMR);
187 /* Atomically lock out dev.c:dev_tint(). */
188 tmp_tbusy = set_bit(0, (void*)&dev->tbusy);
190 ei_local->irqlock = 1;
191 sti();
192 if (ei_local->pingpong) {
193 int output_page;
194 if (ei_local->tx1 == 0) {
195 output_page = ei_local->tx_start_page;
196 ei_local->tx1 = send_length;
197 if (ei_debug && ei_local->tx2 > 0)
198 printk("%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
199 dev->name, ei_local->tx2, ei_local->lasttx,
200 ei_local->txing);
201 } else if (ei_local->tx2 == 0) {
202 output_page = ei_local->tx_start_page + 6;
203 ei_local->tx2 = send_length;
204 if (ei_debug && ei_local->tx1 > 0)
205 printk("%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
206 dev->name, ei_local->tx1, ei_local->lasttx,
207 ei_local->txing);
208 } else {
209 /* We can get to here if we get an rx interrupt and queued
210 a tx packet just before masking 8390 irqs above. */
211 if (ei_debug > 2)
212 printk("%s: No packet buffer space for ping-pong use.\n",
213 dev->name);
214 cli();
215 ei_local->irqlock = 0;
216 dev->tbusy = tmp_tbusy;
217 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
218 sti();
219 return 1;
221 dev->trans_start = jiffies;
222 ei_block_output(dev, length, skb->data, output_page);
223 if (! ei_local->txing) {
224 NS8390_trigger_send(dev, send_length, output_page);
225 if (output_page == ei_local->tx_start_page)
226 ei_local->tx1 = -1, ei_local->lasttx = -1;
227 else
228 ei_local->tx2 = -1, ei_local->lasttx = -2;
229 ei_local->txing = 1;
230 } else
231 ei_local->txqueue++;
232 if (ei_local->tx1 && ei_local->tx2)
233 tmp_tbusy = 1;
234 } else {
235 dev->trans_start = jiffies;
236 ei_block_output(dev, length, skb->data,
237 ei_local->tx_start_page);
238 NS8390_trigger_send(dev, send_length, ei_local->tx_start_page);
239 tmp_tbusy = 1;
240 } /* PINGPONG */
242 if (skb->free)
243 kfree_skb (skb, FREE_WRITE);
245 /* Turn 8390 interrupts back on. */
246 cli();
247 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
248 ei_local->irqlock = 0;
249 dev->tbusy=tmp_tbusy;
250 sti();
251 return 0;
254 /* The typical workload of the driver:
255 Handle the ether interface interrupts. */
256 void ei_interrupt(int reg_ptr)
258 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
259 struct device *dev = (struct device *)(irq2dev_map[irq]);
260 int e8390_base;
261 int interrupts, boguscount = 0;
262 struct ei_device *ei_local;
264 if (dev == NULL) {
265 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
266 return;
268 e8390_base = dev->base_addr;
269 ei_local = (struct ei_device *) dev->priv;
270 if (dev->interrupt || ei_local->irqlock) {
271 /* The "irqlock" check is only for testing. */
272 sti();
273 printk(ei_local->irqlock
274 ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
275 : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
276 dev->name, inb_p(e8390_base + EN0_ISR),
277 inb_p(e8390_base + EN0_IMR));
278 return;
281 dev->interrupt = 1;
282 sti(); /* Allow other interrupts. */
284 /* Change to page 0 and read the intr status reg. */
285 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
286 if (ei_debug > 3)
287 printk("%s: interrupt(isr=%#2.2x).\n", dev->name,
288 inb_p(e8390_base + EN0_ISR));
290 /* !!Assumption!! -- we stay in page 0. Don't break this. */
291 while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
292 && ++boguscount < 20) {
293 if (interrupts & ENISR_RDC) {
294 /* Ack meaningless DMA complete. */
295 outb_p(ENISR_RDC, e8390_base + EN0_ISR);
297 if (interrupts & ENISR_OVER) {
298 ei_rx_overrun(dev);
299 } else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) {
300 /* Got a good (?) packet. */
301 ei_receive(dev);
303 /* Push the next to-transmit packet through. */
304 if (interrupts & ENISR_TX) {
305 ei_tx_intr(dev);
306 } else if (interrupts & ENISR_COUNTERS) {
307 struct ei_device *ei_local = (struct ei_device *) dev->priv;
308 ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
309 ei_local->stat.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1);
310 ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
311 outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR); /* Ack intr. */
314 /* Ignore the transmit errs and reset intr for now. */
315 if (interrupts & ENISR_TX_ERR) {
316 outb_p(ENISR_TX_ERR, e8390_base + EN0_ISR); /* Ack intr. */
318 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
321 if (interrupts && ei_debug) {
322 printk("%s: unknown interrupt %#2x\n", dev->name, interrupts);
323 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
324 outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
326 dev->interrupt = 0;
327 return;
330 /* We have finished a transmit: check for errors and then trigger the next
331 packet to be sent. */
332 static void ei_tx_intr(struct device *dev)
334 int e8390_base = dev->base_addr;
335 int status = inb(e8390_base + EN0_TSR);
336 struct ei_device *ei_local = (struct ei_device *) dev->priv;
338 outb_p(ENISR_TX, e8390_base + EN0_ISR); /* Ack intr. */
340 if (ei_local->pingpong) {
341 ei_local->txqueue--;
342 if (ei_local->tx1 < 0) {
343 if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
344 printk("%s: bogus last_tx_buffer %d, tx1=%d.\n",
345 ei_local->name, ei_local->lasttx, ei_local->tx1);
346 ei_local->tx1 = 0;
347 dev->tbusy = 0;
348 if (ei_local->tx2 > 0) {
349 NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
350 dev->trans_start = jiffies;
351 ei_local->txing = 1;
352 ei_local->tx2 = -1,
353 ei_local->lasttx = 2;
354 } else
355 ei_local->lasttx = 20, ei_local->txing = 0;
356 } else if (ei_local->tx2 < 0) {
357 if (ei_local->lasttx != 2 && ei_local->lasttx != -2)
358 printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
359 ei_local->name, ei_local->lasttx, ei_local->tx2);
360 ei_local->tx2 = 0;
361 dev->tbusy = 0;
362 if (ei_local->tx1 > 0) {
363 NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
364 dev->trans_start = jiffies;
365 ei_local->txing = 1;
366 ei_local->tx1 = -1;
367 ei_local->lasttx = 1;
368 } else
369 ei_local->lasttx = 10, ei_local->txing = 0;
370 } else
371 printk("%s: unexpected TX-done interrupt, lasttx=%d.\n",
372 dev->name, ei_local->lasttx);
373 } else {
374 ei_local->txing = 0;
375 dev->tbusy = 0;
378 /* Do the statistics _after_ we start the next TX. */
379 if (status & ENTSR_PTX)
380 ei_local->stat.tx_packets++;
381 else
382 ei_local->stat.tx_errors++;
383 if (status & ENTSR_COL)
384 ei_local->stat.collisions++;
385 if (status & ENTSR_ABT)
386 ei_local->stat.tx_aborted_errors++;
387 if (status & ENTSR_CRS)
388 ei_local->stat.tx_carrier_errors++;
389 if (status & ENTSR_FU)
390 ei_local->stat.tx_fifo_errors++;
391 if (status & ENTSR_CDH)
392 ei_local->stat.tx_heartbeat_errors++;
393 if (status & ENTSR_OWC)
394 ei_local->stat.tx_window_errors++;
396 mark_bh (INET_BH);
399 /* We have a good packet(s), get it/them out of the buffers. */
401 static void ei_receive(struct device *dev)
403 int e8390_base = dev->base_addr;
404 struct ei_device *ei_local = (struct ei_device *) dev->priv;
405 int rxing_page, this_frame, next_frame, current_offset;
406 int boguscount = 0;
407 struct e8390_pkt_hdr rx_frame;
408 int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page;
410 while (++boguscount < 10) {
411 int pkt_len;
413 /* Get the rx page (incoming packet pointer). */
414 outb_p(E8390_NODMA+E8390_PAGE1, e8390_base + E8390_CMD);
415 rxing_page = inb_p(e8390_base + EN1_CURPAG);
416 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
418 /* Remove one frame from the ring. Boundary is alway a page behind. */
419 this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
420 if (this_frame >= ei_local->stop_page)
421 this_frame = ei_local->rx_start_page;
423 /* Someday we'll omit the previous step, iff we never get this message.*/
424 if (ei_debug > 0 && this_frame != ei_local->current_page)
425 printk("%s: mismatched read page pointers %2x vs %2x.\n",
426 dev->name, this_frame, ei_local->current_page);
428 if (this_frame == rxing_page) /* Read all the frames? */
429 break; /* Done for now */
431 current_offset = this_frame << 8;
432 ei_block_input(dev, sizeof(rx_frame), (char *)&rx_frame,
433 current_offset);
435 pkt_len = rx_frame.count - sizeof(rx_frame);
437 next_frame = this_frame + 1 + ((pkt_len+4)>>8);
439 /* Check for bogosity warned by 3c503 book: the status byte is never
440 written. This happened a lot during testing! This code should be
441 cleaned up someday. */
442 if ( rx_frame.next != next_frame
443 && rx_frame.next != next_frame + 1
444 && rx_frame.next != next_frame - num_rx_pages
445 && rx_frame.next != next_frame + 1 - num_rx_pages) {
446 #ifndef EI_DEBUG
447 ei_local->current_page = rxing_page;
448 outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
449 continue;
450 #else
451 static int last_rx_bogosity = -1;
452 printk("%s: bogus packet header, status=%#2x nxpg=%#2x sz=%#x (at %#4x)\n",
453 dev->name, rx_frame.status, rx_frame.next, rx_frame.count,
454 current_offset);
456 if (ei_local->stat.rx_packets != last_rx_bogosity) {
457 /* Maybe we can avoid resetting the chip... empty the packet ring. */
458 ei_local->current_page = rxing_page;
459 printk("%s: setting next frame to %#2x (nxt=%#2x, rx_frm.nx=%#2x rx_frm.stat=%#2x).\n",
460 dev->name, ei_local->current_page, next_frame,
461 rx_frame.next, rx_frame.status);
462 last_rx_bogosity = ei_local->stat.rx_packets;
463 outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
464 continue;
465 } else {
466 /* Oh no Mr Bill! Last ditch error recovery. */
467 printk("%s: recovery failed, resetting at packet #%d..",
468 dev->name, ei_local->stat.rx_packets);
469 sti();
470 ei_reset_8390(dev);
471 NS8390_init(dev, 1);
472 printk("restarting.\n");
473 return;
475 #endif /* EI8390_NOCHECK */
478 if ((pkt_len < 46 || pkt_len > 1535) && ei_debug)
479 printk("%s: bogus packet size, status=%#2x nxpg=%#2x size=%#x\n",
480 dev->name, rx_frame.status, rx_frame.next, rx_frame.count);
481 if ((rx_frame.status & 0x0F) == ENRSR_RXOK) {
482 int sksize = sizeof(struct sk_buff) + pkt_len;
483 struct sk_buff *skb;
485 skb = alloc_skb(sksize, GFP_ATOMIC);
486 if (skb == NULL) {
487 if (ei_debug)
488 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
489 dev->name, sksize);
490 ei_local->stat.rx_dropped++;
491 break;
492 } else {
493 skb->mem_len = sksize;
494 skb->mem_addr = skb;
495 skb->len = pkt_len;
496 skb->dev = dev;
498 /* 'skb->data' points to the start of sk_buff data area. */
499 ei_block_input(dev, pkt_len, (char *) skb->data,
500 current_offset + sizeof(rx_frame));
501 #ifdef HAVE_NETIF_RX
502 netif_rx(skb);
503 #else
504 skb->lock = 0;
505 if (dev_rint((unsigned char*)skb, pkt_len, IN_SKBUFF, dev)) {
506 kfree_skbmem(skb, sksize);
507 lp->stats.rx_dropped++;
508 break;
510 #endif
511 ei_local->stat.rx_packets++;
513 } else {
514 int errs = rx_frame.status;
515 if (ei_debug)
516 printk("%s: bogus packet, status=%#2x nxpg=%#2x size=%d\n",
517 dev->name, rx_frame.status, rx_frame.next, rx_frame.count);
518 if (errs & ENRSR_FO)
519 ei_local->stat.rx_fifo_errors++;
521 next_frame = rx_frame.next;
523 /* This should never happen, it's here for debugging. */
524 if (next_frame >= ei_local->stop_page) {
525 printk("%s: next frame inconsistency, %#2x..", dev->name, next_frame);
526 next_frame = ei_local->rx_start_page;
528 ei_local->current_page += 1 + ((pkt_len+4)>>8);
529 ei_local->current_page = next_frame;
530 outb(next_frame-1, e8390_base+EN0_BOUNDARY);
532 /* If any worth-while packets have been received, dev_rint()
533 has done a mark_bh(INET_BH) for us and will work on them
534 when we get to the bottom-half routine. */
536 /* Bug alert! Reset ENISR_OVER to avoid spurious overruns! */
537 outb_p(ENISR_RX+ENISR_RX_ERR+ENISR_OVER, e8390_base+EN0_ISR);
538 return;
541 /* We have a receiver overrun: we have to kick the 8390 to get it started
542 again.*/
543 static void ei_rx_overrun(struct device *dev)
545 int e8390_base = dev->base_addr;
546 int reset_start_time = jiffies;
547 struct ei_device *ei_local = (struct ei_device *) dev->priv;
549 /* We should already be stopped and in page0. Remove after testing. */
550 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
552 if (ei_debug)
553 printk("%s: Receiver overrun.\n", dev->name);
554 ei_local->stat.rx_over_errors++;
556 /* The we.c driver does dummy = inb_p( RBCR[01] ); at this point.
557 It might mean something -- magic to speed up a reset? A 8390 bug?*/
559 /* Wait for reset in case the NIC is doing a tx or rx. This could take up to
560 1.5msec, but we have no way of timing something in that range. The 'jiffies'
561 are just a sanity check. */
562 while ((inb_p(e8390_base+EN0_ISR) & ENISR_RESET) == 0)
563 if (jiffies - reset_start_time > 1) {
564 printk("%s: reset did not complete at ei_rx_overrun.\n",
565 dev->name);
566 NS8390_init(dev, 1);
567 return;
570 /* Remove packets right away. */
571 ei_receive(dev);
573 outb_p(0xff, e8390_base+EN0_ISR);
574 /* Generic 8390 insns to start up again, same as in open_8390(). */
575 outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
576 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
579 static struct enet_statistics *get_stats(struct device *dev)
581 short ioaddr = dev->base_addr;
582 struct ei_device *ei_local = (struct ei_device *) dev->priv;
584 /* Read the counter registers, assuming we are in page 0. */
585 ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
586 ei_local->stat.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1);
587 ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
589 return &ei_local->stat;
592 #ifdef HAVE_MULTICAST
593 /* Set or clear the multicast filter for this adaptor.
594 num_addrs == -1 Promiscuous mode, receive all packets
595 num_addrs == 0 Normal mode, clear multicast list
596 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
597 . best-effort filtering.
599 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs)
601 short ioaddr = dev->base_addr;
603 if (num_addrs > 0) {
604 /* The multicast-accept list is initialized to accept-all, and we
605 rely on higher-level filtering for now. */
606 outb_p(E8390_RXCONFIG | 0x08, ioaddr + EN0_RXCR);
607 } else if (num_addrs < 0)
608 outb_p(E8390_RXCONFIG | 0x10, ioaddr + EN0_RXCR);
609 else
610 outb_p(E8390_RXCONFIG, ioaddr + EN0_RXCR);
612 #endif
614 /* Initialize the rest of the 8390 device structure. */
615 int ethdev_init(struct device *dev)
617 int i;
619 if (ei_debug > 1)
620 printk(version);
622 if (dev->priv == NULL) {
623 struct ei_device *ei_local;
625 dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
626 memset(dev->priv, 0, sizeof(struct ei_device));
627 ei_local = (struct ei_device *)dev->priv;
628 #ifndef NO_PINGPONG
629 ei_local->pingpong = 1;
630 #endif
633 /* The open call may be overridden by the card-specific code. */
634 if (dev->open == NULL)
635 dev->open = &ei_open;
636 /* We should have a dev->stop entry also. */
637 dev->hard_start_xmit = &ei_start_xmit;
638 dev->get_stats = get_stats;
639 #ifdef HAVE_MULTICAST
640 dev->set_multicast_list = &set_multicast_list;
641 #endif
643 for (i = 0; i < DEV_NUMBUFFS; i++)
644 dev->buffs[i] = NULL;
646 dev->hard_header = eth_header;
647 dev->add_arp = eth_add_arp;
648 dev->queue_xmit = dev_queue_xmit;
649 dev->rebuild_header = eth_rebuild_header;
650 dev->type_trans = eth_type_trans;
652 dev->type = ARPHRD_ETHER;
653 dev->hard_header_len = ETH_HLEN;
654 dev->mtu = 1500; /* eth_mtu */
655 dev->addr_len = ETH_ALEN;
656 for (i = 0; i < ETH_ALEN; i++) {
657 dev->broadcast[i]=0xff;
660 /* New-style flags. */
661 dev->flags = IFF_BROADCAST;
662 dev->family = AF_INET;
663 dev->pa_addr = 0;
664 dev->pa_brdaddr = 0;
665 dev->pa_mask = 0;
666 dev->pa_alen = sizeof(unsigned long);
668 return 0;
672 /* This page of functions should be 8390 generic */
673 /* Follow National Semi's recommendations for initializing the "NIC". */
674 void NS8390_init(struct device *dev, int startp)
676 int e8390_base = dev->base_addr;
677 struct ei_device *ei_local = (struct ei_device *) dev->priv;
678 int i;
679 int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
681 /* Follow National Semi's recommendations for initing the DP83902. */
682 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base); /* 0x21 */
683 outb_p(endcfg, e8390_base + EN0_DCFG); /* 0x48 or 0x49 */
684 /* Clear the remote byte count registers. */
685 outb_p(0x00, e8390_base + EN0_RCNTLO);
686 outb_p(0x00, e8390_base + EN0_RCNTHI);
687 /* Set to monitor and loopback mode -- this is vital!. */
688 outb_p(E8390_RXOFF, e8390_base + EN0_RXCR); /* 0x20 */
689 outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
690 /* Set the transmit page and receive ring. */
691 outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
692 ei_local->tx1 = ei_local->tx2 = 0;
693 outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
694 outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/
695 ei_local->current_page = ei_local->rx_start_page; /* assert boundary+1 */
696 outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
697 /* Clear the pending interrupts and mask. */
698 outb_p(0xFF, e8390_base + EN0_ISR);
699 outb_p(0x00, e8390_base + EN0_IMR);
701 /* Copy the station address into the DS8390 registers,
702 and set the multicast hash bitmap to receive all multicasts. */
703 cli();
704 outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base); /* 0x61 */
705 for(i = 0; i < 6; i++) {
706 outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS + i);
708 /* Initialize the multicast list to accept-all. If we enable multicast
709 the higher levels can do the filtering. */
710 for(i = 0; i < 8; i++)
711 outb_p(0xff, e8390_base + EN1_MULT + i);
713 outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
714 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base);
715 sti();
716 if (startp) {
717 outb_p(0xff, e8390_base + EN0_ISR);
718 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
719 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base);
720 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
721 /* 3c503 TechMan says rxconfig only after the NIC is started. */
722 outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR); /* rx on, */
724 return;
727 /* Trigger a transmit start, assuming the length is valid. */
728 static void NS8390_trigger_send(struct device *dev, unsigned int length,
729 int start_page)
731 int e8390_base = dev->base_addr;
733 ei_status.txing = 1;
734 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base);
736 if (inb_p(e8390_base) & E8390_TRANS) {
737 printk("%s: trigger_send() called with the transmitter busy.\n",
738 dev->name);
739 return;
741 outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
742 outb_p(length >> 8, e8390_base + EN0_TCNTHI);
743 outb_p(start_page, e8390_base + EN0_TPSR);
744 outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base);
745 return;
750 * Local variables:
751 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 8390.c"
752 * version-control: t
753 * kept-new-versions: 5
754 * tab-width: 4
755 * End: