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