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