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