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