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