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