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