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