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