This source file includes following definitions.
- ei_open
- ei_start_xmit
- ei_interrupt
- ei_tx_intr
- ei_receive
- ei_rx_overrun
- get_stats
- set_multicast_list
- ethdev_init
- NS8390_init
- NS8390_trigger_send
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 static char *version =
19 "8390.c:v0.99-15e 2/16/94 Donald Becker (becker@super.org)\n";
20 #include <linux/config.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <linux/config.h>
35 #include <linux/kernel.h>
36 #include <linux/sched.h>
37 #include <linux/fs.h>
38 #include <linux/types.h>
39 #include <linux/ptrace.h>
40 #include <linux/string.h>
41 #include <asm/system.h>
42 #include <asm/segment.h>
43 #include <asm/bitops.h>
44 #include <asm/io.h>
45 #include <errno.h>
46 #include <linux/fcntl.h>
47 #include <linux/in.h>
48 #include <linux/interrupt.h>
49
50 #include "dev.h"
51 #include "eth.h"
52 #include "ip.h"
53 #include "protocol.h"
54 #include "tcp.h"
55 #include "skbuff.h"
56 #include "sock.h"
57 #include "arp.h"
58
59 #include "8390.h"
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 #define ei_reset_8390 (ei_local->reset_8390)
78 #define ei_block_output (ei_local->block_output)
79 #define ei_block_input (ei_local->block_input)
80
81
82 #ifdef EI_DEBUG
83 int ei_debug = EI_DEBUG;
84 #else
85 int ei_debug = 1;
86 #endif
87
88
89
90 static int high_water_mark = 0;
91
92
93 int ei_open(struct device *dev);
94 void ei_interrupt(int reg_ptr);
95
96 static void ei_tx_intr(struct device *dev);
97 static void ei_receive(struct device *dev);
98 static void ei_rx_overrun(struct device *dev);
99
100
101 void NS8390_init(struct device *dev, int startp);
102 static void NS8390_trigger_send(struct device *dev, unsigned int length,
103 int start_page);
104 #ifdef HAVE_MULTICAST
105 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
106 #endif
107
108 struct sigaction ei_sigaction = { ei_interrupt, 0, 0, NULL, };
109
110
111
112
113
114 int ei_open(struct device *dev)
115 {
116 struct ei_device *ei_local = (struct ei_device *) dev->priv;
117
118 if ( ! ei_local) {
119 printk("%s: Opening a non-existent physical device\n", dev->name);
120 return ENXIO;
121 }
122
123 irq2dev_map[dev->irq] = dev;
124 NS8390_init(dev, 1);
125 dev->start = 1;
126 ei_local->irqlock = 0;
127 return 0;
128 }
129
130 static int ei_start_xmit(struct sk_buff *skb, struct device *dev)
131 {
132 int e8390_base = dev->base_addr;
133 struct ei_device *ei_local = (struct ei_device *) dev->priv;
134 int length, send_length;
135
136
137
138
139
140
141 if (dev->tbusy) {
142 int txsr = inb(e8390_base+EN0_TSR), isr;
143 int tickssofar = jiffies - dev->trans_start;
144 if (tickssofar < 10 || (tickssofar < 15 && ! (txsr & ENTSR_PTX))) {
145 return 1;
146 }
147 isr = inb(e8390_base+EN0_ISR);
148 printk("%s: transmit timed out, TX status %#2x, ISR %#2x.\n",
149 dev->name, txsr, isr);
150
151 if (isr)
152 printk("%s: Possible IRQ conflict on IRQ%d?\n", dev->name, dev->irq);
153 else {
154
155 printk("%s: Possible network cable problem?\n", dev->name);
156 ei_local->interface_num ^= 1;
157 }
158
159 ei_reset_8390(dev);
160 NS8390_init(dev, 1);
161 dev->trans_start = jiffies;
162 }
163
164
165
166
167 if (skb == NULL) {
168 dev_tint(dev);
169 return 0;
170 }
171
172 if (!skb->arp && dev->rebuild_header(skb->data, dev)) {
173 skb->dev = dev;
174 arp_queue (skb);
175 return 0;
176 }
177 skb->arp=1;
178
179 length = skb->len;
180 if (skb->len <= 0)
181 return 0;
182
183
184 if (set_bit(0, (void*)&dev->tbusy) != 0) {
185 printk("%s: Transmitter access conflict.\n", dev->name);
186 return 1;
187 }
188
189
190 outb(0x00, e8390_base + EN0_IMR);
191 ei_local->irqlock = 1;
192
193 send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
194
195 if (ei_local->pingpong) {
196 int output_page;
197 if (ei_local->tx1 == 0) {
198 output_page = ei_local->tx_start_page;
199 ei_local->tx1 = send_length;
200 if (ei_debug && ei_local->tx2 > 0)
201 printk("%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
202 dev->name, ei_local->tx2, ei_local->lasttx,
203 ei_local->txing);
204 } else if (ei_local->tx2 == 0) {
205 output_page = ei_local->tx_start_page + 6;
206 ei_local->tx2 = send_length;
207 if (ei_debug && ei_local->tx1 > 0)
208 printk("%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
209 dev->name, ei_local->tx1, ei_local->lasttx,
210 ei_local->txing);
211 } else {
212 if (ei_debug)
213 printk("%s: No packet buffer space for ping-pong use.\n",
214 dev->name);
215 ei_local->irqlock = 0;
216 dev->tbusy = 1;
217 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
218 return 1;
219 }
220 ei_block_output(dev, length, skb->data, output_page);
221 if (! ei_local->txing) {
222 NS8390_trigger_send(dev, send_length, output_page);
223 dev->trans_start = jiffies;
224 if (output_page == ei_local->tx_start_page)
225 ei_local->tx1 = -1, ei_local->lasttx = -1;
226 else
227 ei_local->tx2 = -1, ei_local->lasttx = -2;
228 ei_local->txing = 1;
229 } else
230 ei_local->txqueue++;
231
232 dev->tbusy = (ei_local->tx1 && ei_local->tx2);
233 } else {
234 ei_block_output(dev, length, skb->data, ei_local->tx_start_page);
235 NS8390_trigger_send(dev, send_length, ei_local->tx_start_page);
236 dev->trans_start = jiffies;
237 dev->tbusy = 1;
238 }
239
240
241 ei_local->irqlock = 0;
242 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
243
244 if (skb->free)
245 kfree_skb (skb, FREE_WRITE);
246
247 return 0;
248 }
249
250
251
252 void ei_interrupt(int reg_ptr)
253 {
254 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
255 struct device *dev = (struct device *)(irq2dev_map[irq]);
256 int e8390_base;
257 int interrupts, boguscount = 0;
258 struct ei_device *ei_local;
259
260 if (dev == NULL) {
261 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
262 return;
263 }
264 e8390_base = dev->base_addr;
265 ei_local = (struct ei_device *) dev->priv;
266 if (dev->interrupt || ei_local->irqlock) {
267
268 sti();
269 printk(ei_local->irqlock
270 ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
271 : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
272 dev->name, inb_p(e8390_base + EN0_ISR),
273 inb_p(e8390_base + EN0_IMR));
274 return;
275 }
276
277 dev->interrupt = 1;
278 sti();
279
280
281 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
282 if (ei_debug > 3)
283 printk("%s: interrupt(isr=%#2.2x).\n", dev->name,
284 inb_p(e8390_base + EN0_ISR));
285
286
287 while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
288 && ++boguscount < 5) {
289 if (interrupts & ENISR_RDC) {
290
291 outb_p(ENISR_RDC, e8390_base + EN0_ISR);
292 }
293 if (interrupts & ENISR_OVER) {
294 ei_rx_overrun(dev);
295 } else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) {
296
297 ei_receive(dev);
298 }
299
300 if (interrupts & ENISR_TX) {
301 ei_tx_intr(dev);
302 } else if (interrupts & ENISR_COUNTERS) {
303 struct ei_device *ei_local = (struct ei_device *) dev->priv;
304 ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
305 ei_local->stat.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1);
306 ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
307 outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR);
308 }
309
310
311 if (interrupts & ENISR_TX_ERR) {
312 outb_p(ENISR_TX_ERR, e8390_base + EN0_ISR);
313 }
314 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
315 }
316
317 if (interrupts && ei_debug) {
318 printk("%s: unknown interrupt %#2x\n", dev->name, interrupts);
319 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
320 outb_p(0xff, e8390_base + EN0_ISR);
321 }
322 dev->interrupt = 0;
323 return;
324 }
325
326
327
328 static void ei_tx_intr(struct device *dev)
329 {
330 int e8390_base = dev->base_addr;
331 int status = inb(e8390_base + EN0_TSR);
332 struct ei_device *ei_local = (struct ei_device *) dev->priv;
333
334 outb_p(ENISR_TX, e8390_base + EN0_ISR);
335
336 if (ei_local->pingpong) {
337 ei_local->txqueue--;
338 if (ei_local->tx1 < 0) {
339 if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
340 printk("%s: bogus last_tx_buffer %d, tx1=%d.\n",
341 ei_local->name, ei_local->lasttx, ei_local->tx1);
342 ei_local->tx1 = 0;
343 dev->tbusy = 0;
344 if (ei_local->tx2 > 0) {
345 NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
346 dev->trans_start = jiffies;
347 ei_local->txing = 1;
348 ei_local->tx2 = -1,
349 ei_local->lasttx = 2;
350 } else
351 ei_local->lasttx = 20, ei_local->txing = 0;
352 } else if (ei_local->tx2 < 0) {
353 if (ei_local->lasttx != 2 && ei_local->lasttx != -2)
354 printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
355 ei_local->name, ei_local->lasttx, ei_local->tx2);
356 ei_local->tx2 = 0;
357 dev->tbusy = 0;
358 if (ei_local->tx1 > 0) {
359 NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
360 dev->trans_start = jiffies;
361 ei_local->txing = 1;
362 ei_local->tx1 = -1;
363 ei_local->lasttx = 1;
364 } else
365 ei_local->lasttx = 10, ei_local->txing = 0;
366 } else
367 printk("%s: unexpected TX-done interrupt, lasttx=%d.\n",
368 dev->name, ei_local->lasttx);
369 } else {
370 ei_local->txing = 0;
371 dev->tbusy = 0;
372 }
373
374
375 if (status & ENTSR_COL) ei_local->stat.collisions++;
376 if (status & ENTSR_PTX)
377 ei_local->stat.tx_packets++;
378 else {
379 ei_local->stat.tx_errors++;
380 if (status & ENTSR_ABT) ei_local->stat.tx_aborted_errors++;
381 if (status & ENTSR_CRS) ei_local->stat.tx_carrier_errors++;
382 if (status & ENTSR_FU) ei_local->stat.tx_fifo_errors++;
383 if (status & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++;
384 if (status & ENTSR_OWC) ei_local->stat.tx_window_errors++;
385 }
386
387 mark_bh (INET_BH);
388 }
389
390
391
392 static void ei_receive(struct device *dev)
393 {
394 int e8390_base = dev->base_addr;
395 struct ei_device *ei_local = (struct ei_device *) dev->priv;
396 int rxing_page, this_frame, next_frame, current_offset;
397 int rx_pkt_count = 0;
398 struct e8390_pkt_hdr rx_frame;
399 int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page;
400
401 while (++rx_pkt_count < 10) {
402 int pkt_len;
403
404
405 outb_p(E8390_NODMA+E8390_PAGE1, e8390_base + E8390_CMD);
406 rxing_page = inb_p(e8390_base + EN1_CURPAG);
407 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
408
409
410 this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
411 if (this_frame >= ei_local->stop_page)
412 this_frame = ei_local->rx_start_page;
413
414
415
416 if (ei_debug > 0 && this_frame != ei_local->current_page)
417 printk("%s: mismatched read page pointers %2x vs %2x.\n",
418 dev->name, this_frame, ei_local->current_page);
419
420 if (this_frame == rxing_page)
421 break;
422
423 current_offset = this_frame << 8;
424 ei_block_input(dev, sizeof(rx_frame), (char *)&rx_frame,
425 current_offset);
426
427 pkt_len = rx_frame.count - sizeof(rx_frame);
428
429 next_frame = this_frame + 1 + ((pkt_len+4)>>8);
430
431
432
433
434 if (rx_frame.next != next_frame
435 && rx_frame.next != next_frame + 1
436 && rx_frame.next != next_frame - num_rx_pages
437 && rx_frame.next != next_frame + 1 - num_rx_pages) {
438 ei_local->current_page = rxing_page;
439 outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
440 ei_local->stat.rx_errors++;
441 continue;
442 }
443
444 if (pkt_len < 60 || pkt_len > 1518) {
445 if (ei_debug)
446 printk("%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
447 dev->name, rx_frame.count, rx_frame.status,
448 rx_frame.next);
449 ei_local->stat.rx_errors++;
450 } else if ((rx_frame.status & 0x0F) == ENRSR_RXOK) {
451 int sksize = sizeof(struct sk_buff) + pkt_len;
452 struct sk_buff *skb;
453
454 skb = alloc_skb(sksize, GFP_ATOMIC);
455 if (skb == NULL) {
456 if (ei_debug)
457 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
458 dev->name, sksize);
459 ei_local->stat.rx_dropped++;
460 break;
461 } else {
462 skb->mem_len = sksize;
463 skb->mem_addr = skb;
464 skb->len = pkt_len;
465 skb->dev = dev;
466
467 ei_block_input(dev, pkt_len, (char *) skb->data,
468 current_offset + sizeof(rx_frame));
469 netif_rx(skb);
470 ei_local->stat.rx_packets++;
471 }
472 } else {
473 int errs = rx_frame.status;
474 if (ei_debug)
475 printk("%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
476 dev->name, rx_frame.status, rx_frame.next,
477 rx_frame.count);
478 if (errs & ENRSR_FO)
479 ei_local->stat.rx_fifo_errors++;
480 }
481 next_frame = rx_frame.next;
482
483
484 if (next_frame >= ei_local->stop_page) {
485 printk("%s: next frame inconsistency, %#2x..", dev->name,
486 next_frame);
487 next_frame = ei_local->rx_start_page;
488 }
489 ei_local->current_page = next_frame;
490 outb(next_frame-1, e8390_base+EN0_BOUNDARY);
491 }
492
493
494
495
496
497 if (rx_pkt_count > high_water_mark)
498 high_water_mark = rx_pkt_count;
499
500
501 outb_p(ENISR_RX+ENISR_RX_ERR+ENISR_OVER, e8390_base+EN0_ISR);
502 return;
503 }
504
505
506
507 static void ei_rx_overrun(struct device *dev)
508 {
509 int e8390_base = dev->base_addr;
510 int reset_start_time = jiffies;
511 struct ei_device *ei_local = (struct ei_device *) dev->priv;
512
513
514 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
515
516 if (ei_debug)
517 printk("%s: Receiver overrun.\n", dev->name);
518 ei_local->stat.rx_over_errors++;
519
520
521
522
523
524
525
526
527 while ((inb_p(e8390_base+EN0_ISR) & ENISR_RESET) == 0)
528 if (jiffies - reset_start_time > 1) {
529 printk("%s: reset did not complete at ei_rx_overrun.\n",
530 dev->name);
531 NS8390_init(dev, 1);
532 return;
533 }
534
535
536 ei_receive(dev);
537
538 outb_p(0xff, e8390_base+EN0_ISR);
539
540 outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
541 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR);
542 }
543
544 static struct enet_statistics *get_stats(struct device *dev)
545 {
546 short ioaddr = dev->base_addr;
547 struct ei_device *ei_local = (struct ei_device *) dev->priv;
548
549
550 ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
551 ei_local->stat.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1);
552 ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
553
554 return &ei_local->stat;
555 }
556
557 #ifdef HAVE_MULTICAST
558
559
560
561
562
563
564 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs)
565 {
566 short ioaddr = dev->base_addr;
567
568 if (num_addrs > 0) {
569
570
571 outb_p(E8390_RXCONFIG | 0x08, ioaddr + EN0_RXCR);
572 } else if (num_addrs < 0)
573 outb_p(E8390_RXCONFIG | 0x10, ioaddr + EN0_RXCR);
574 else
575 outb_p(E8390_RXCONFIG, ioaddr + EN0_RXCR);
576 }
577 #endif
578
579
580 int ethdev_init(struct device *dev)
581 {
582 int i;
583
584 if (ei_debug > 1)
585 printk(version);
586
587 if (dev->priv == NULL) {
588 struct ei_device *ei_local;
589
590 dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
591 memset(dev->priv, 0, sizeof(struct ei_device));
592 ei_local = (struct ei_device *)dev->priv;
593 #ifndef NO_PINGPONG
594 ei_local->pingpong = 1;
595 #endif
596 }
597
598
599 if (dev->open == NULL)
600 dev->open = &ei_open;
601
602 dev->hard_start_xmit = &ei_start_xmit;
603 dev->get_stats = get_stats;
604 #ifdef HAVE_MULTICAST
605 dev->set_multicast_list = &set_multicast_list;
606 #endif
607
608 for (i = 0; i < DEV_NUMBUFFS; i++)
609 dev->buffs[i] = NULL;
610
611 dev->hard_header = eth_header;
612 dev->add_arp = eth_add_arp;
613 dev->queue_xmit = dev_queue_xmit;
614 dev->rebuild_header = eth_rebuild_header;
615 dev->type_trans = eth_type_trans;
616
617 dev->type = ARPHRD_ETHER;
618 dev->hard_header_len = ETH_HLEN;
619 dev->mtu = 1500;
620 dev->addr_len = ETH_ALEN;
621 for (i = 0; i < ETH_ALEN; i++) {
622 dev->broadcast[i]=0xff;
623 }
624
625
626 dev->flags = IFF_BROADCAST;
627 dev->family = AF_INET;
628 dev->pa_addr = 0;
629 dev->pa_brdaddr = 0;
630 dev->pa_mask = 0;
631 dev->pa_alen = sizeof(unsigned long);
632
633 return 0;
634 }
635
636
637
638
639 void NS8390_init(struct device *dev, int startp)
640 {
641 int e8390_base = dev->base_addr;
642 struct ei_device *ei_local = (struct ei_device *) dev->priv;
643 int i;
644 int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
645
646
647 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base);
648 outb_p(endcfg, e8390_base + EN0_DCFG);
649
650 outb_p(0x00, e8390_base + EN0_RCNTLO);
651 outb_p(0x00, e8390_base + EN0_RCNTHI);
652
653 outb_p(E8390_RXOFF, e8390_base + EN0_RXCR);
654 outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
655
656 outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
657 ei_local->tx1 = ei_local->tx2 = 0;
658 outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
659 outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY);
660 ei_local->current_page = ei_local->rx_start_page;
661 outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
662
663 outb_p(0xFF, e8390_base + EN0_ISR);
664 outb_p(0x00, e8390_base + EN0_IMR);
665
666
667
668 cli();
669 outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base);
670 for(i = 0; i < 6; i++) {
671 outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS + i);
672 }
673
674
675 for(i = 0; i < 8; i++)
676 outb_p(0xff, e8390_base + EN1_MULT + i);
677
678 outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
679 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base);
680 sti();
681 dev->tbusy = 0;
682 dev->interrupt = 0;
683 ei_local->tx1 = ei_local->tx2 = 0;
684 ei_local->txing = 0;
685 if (startp) {
686 outb_p(0xff, e8390_base + EN0_ISR);
687 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
688 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base);
689 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR);
690
691 outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
692 }
693 return;
694 }
695
696
697 static void NS8390_trigger_send(struct device *dev, unsigned int length,
698 int start_page)
699 {
700 int e8390_base = dev->base_addr;
701
702 ei_status.txing = 1;
703 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base);
704
705 if (inb_p(e8390_base) & E8390_TRANS) {
706 printk("%s: trigger_send() called with the transmitter busy.\n",
707 dev->name);
708 return;
709 }
710 outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
711 outb_p(length >> 8, e8390_base + EN0_TCNTHI);
712 outb_p(start_page, e8390_base + EN0_TPSR);
713 outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base);
714 return;
715 }
716
717
718
719
720
721
722
723
724
725
726