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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50static const char version[] =
51 "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
52
53#include <linux/module.h>
54#include <linux/kernel.h>
55#include <linux/jiffies.h>
56#include <linux/fs.h>
57#include <linux/types.h>
58#include <linux/string.h>
59#include <asm/system.h>
60#include <asm/uaccess.h>
61#include <asm/bitops.h>
62#include <asm/io.h>
63#include <asm/irq.h>
64#include <linux/delay.h>
65#include <linux/errno.h>
66#include <linux/fcntl.h>
67#include <linux/in.h>
68#include <linux/interrupt.h>
69#include <linux/init.h>
70#include <linux/crc32.h>
71
72#include <linux/netdevice.h>
73#include <linux/etherdevice.h>
74
75#define NS8390_CORE
76#include "8390.h"
77
78#define BUG_83C690
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98#define ei_reset_8390 (ei_local->reset_8390)
99#define ei_block_output (ei_local->block_output)
100#define ei_block_input (ei_local->block_input)
101#define ei_get_8390_hdr (ei_local->get_8390_hdr)
102
103
104#ifndef ei_debug
105int ei_debug = 1;
106#endif
107
108
109static void ei_tx_intr(struct net_device *dev);
110static void ei_tx_err(struct net_device *dev);
111static void ei_tx_timeout(struct net_device *dev);
112static void ei_receive(struct net_device *dev);
113static void ei_rx_overrun(struct net_device *dev);
114
115
116static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
117 int start_page);
118static void set_multicast_list(struct net_device *dev);
119static void do_set_multicast_list(struct net_device *dev);
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157int ei_open(struct net_device *dev)
158{
159 unsigned long flags;
160 struct ei_device *ei_local = (struct ei_device *) dev->priv;
161
162
163 if (ei_local == NULL)
164 {
165 printk(KERN_EMERG "%s: ei_open passed a non-existent device!\n", dev->name);
166 return -ENXIO;
167 }
168
169
170
171 if (dev->tx_timeout == NULL)
172 dev->tx_timeout = ei_tx_timeout;
173 if (dev->watchdog_timeo <= 0)
174 dev->watchdog_timeo = TX_TIMEOUT;
175
176
177
178
179
180
181 spin_lock_irqsave(&ei_local->page_lock, flags);
182 NS8390_init(dev, 1);
183
184
185 netif_start_queue(dev);
186 spin_unlock_irqrestore(&ei_local->page_lock, flags);
187 ei_local->irqlock = 0;
188 return 0;
189}
190
191
192
193
194
195
196
197int ei_close(struct net_device *dev)
198{
199 struct ei_device *ei_local = (struct ei_device *) dev->priv;
200 unsigned long flags;
201
202
203
204
205
206 spin_lock_irqsave(&ei_local->page_lock, flags);
207 NS8390_init(dev, 0);
208 spin_unlock_irqrestore(&ei_local->page_lock, flags);
209 netif_stop_queue(dev);
210 return 0;
211}
212
213
214
215
216
217
218
219
220
221void ei_tx_timeout(struct net_device *dev)
222{
223 long e8390_base = dev->base_addr;
224 struct ei_device *ei_local = (struct ei_device *) dev->priv;
225 int txsr, isr, tickssofar = jiffies - dev->trans_start;
226 unsigned long flags;
227
228 ei_local->stat.tx_errors++;
229
230 spin_lock_irqsave(&ei_local->page_lock, flags);
231 txsr = inb(e8390_base+EN0_TSR);
232 isr = inb(e8390_base+EN0_ISR);
233 spin_unlock_irqrestore(&ei_local->page_lock, flags);
234
235 printk(KERN_DEBUG "%s: Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n",
236 dev->name, (txsr & ENTSR_ABT) ? "excess collisions." :
237 (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar);
238
239 if (!isr && !ei_local->stat.tx_packets)
240 {
241
242 ei_local->interface_num ^= 1;
243 }
244
245
246
247 disable_irq_nosync(dev->irq);
248 spin_lock(&ei_local->page_lock);
249
250
251 ei_reset_8390(dev);
252 NS8390_init(dev, 1);
253
254 spin_unlock(&ei_local->page_lock);
255 enable_irq(dev->irq);
256 netif_wake_queue(dev);
257}
258
259
260
261
262
263
264
265
266
267static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
268{
269 long e8390_base = dev->base_addr;
270 struct ei_device *ei_local = (struct ei_device *) dev->priv;
271 int length, send_length, output_page;
272 unsigned long flags;
273
274 length = skb->len;
275
276
277
278
279
280
281 spin_lock_irqsave(&ei_local->page_lock, flags);
282 outb_p(0x00, e8390_base + EN0_IMR);
283 spin_unlock_irqrestore(&ei_local->page_lock, flags);
284
285
286
287
288
289
290 disable_irq_nosync(dev->irq);
291
292 spin_lock(&ei_local->page_lock);
293
294 ei_local->irqlock = 1;
295
296 send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
297
298#ifdef EI_PINGPONG
299
300
301
302
303
304
305
306
307
308 if (ei_local->tx1 == 0)
309 {
310 output_page = ei_local->tx_start_page;
311 ei_local->tx1 = send_length;
312 if (ei_debug && ei_local->tx2 > 0)
313 printk(KERN_DEBUG "%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
314 dev->name, ei_local->tx2, ei_local->lasttx, ei_local->txing);
315 }
316 else if (ei_local->tx2 == 0)
317 {
318 output_page = ei_local->tx_start_page + TX_1X_PAGES;
319 ei_local->tx2 = send_length;
320 if (ei_debug && ei_local->tx1 > 0)
321 printk(KERN_DEBUG "%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
322 dev->name, ei_local->tx1, ei_local->lasttx, ei_local->txing);
323 }
324 else
325 {
326 if (ei_debug)
327 printk(KERN_DEBUG "%s: No Tx buffers free! tx1=%d tx2=%d last=%d\n",
328 dev->name, ei_local->tx1, ei_local->tx2, ei_local->lasttx);
329 ei_local->irqlock = 0;
330 netif_stop_queue(dev);
331 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
332 spin_unlock(&ei_local->page_lock);
333 enable_irq(dev->irq);
334 ei_local->stat.tx_errors++;
335 return 1;
336 }
337
338
339
340
341
342
343
344 ei_block_output(dev, length, skb->data, output_page);
345 if (! ei_local->txing)
346 {
347 ei_local->txing = 1;
348 NS8390_trigger_send(dev, send_length, output_page);
349 dev->trans_start = jiffies;
350 if (output_page == ei_local->tx_start_page)
351 {
352 ei_local->tx1 = -1;
353 ei_local->lasttx = -1;
354 }
355 else
356 {
357 ei_local->tx2 = -1;
358 ei_local->lasttx = -2;
359 }
360 }
361 else ei_local->txqueue++;
362
363 if (ei_local->tx1 && ei_local->tx2)
364 netif_stop_queue(dev);
365 else
366 netif_start_queue(dev);
367
368#else
369
370
371
372
373
374
375
376 ei_block_output(dev, length, skb->data, ei_local->tx_start_page);
377 ei_local->txing = 1;
378 NS8390_trigger_send(dev, send_length, ei_local->tx_start_page);
379 dev->trans_start = jiffies;
380 netif_stop_queue(dev);
381
382#endif
383
384
385 ei_local->irqlock = 0;
386 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
387
388 spin_unlock(&ei_local->page_lock);
389 enable_irq(dev->irq);
390
391 dev_kfree_skb (skb);
392 ei_local->stat.tx_bytes += send_length;
393
394 return 0;
395}
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410void ei_interrupt(int irq, void *dev_id, struct pt_regs * regs)
411{
412 struct net_device *dev = dev_id;
413 long e8390_base;
414 int interrupts, nr_serviced = 0;
415 struct ei_device *ei_local;
416
417 if (dev == NULL)
418 {
419 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
420 return;
421 }
422
423 e8390_base = dev->base_addr;
424 ei_local = (struct ei_device *) dev->priv;
425
426
427
428
429
430 spin_lock(&ei_local->page_lock);
431
432 if (ei_local->irqlock)
433 {
434#if 1
435
436 printk(ei_local->irqlock
437 ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
438 : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
439 dev->name, inb_p(e8390_base + EN0_ISR),
440 inb_p(e8390_base + EN0_IMR));
441#endif
442 spin_unlock(&ei_local->page_lock);
443 return;
444 }
445
446
447 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
448 if (ei_debug > 3)
449 printk(KERN_DEBUG "%s: interrupt(isr=%#2.2x).\n", dev->name,
450 inb_p(e8390_base + EN0_ISR));
451
452
453 while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
454 && ++nr_serviced < MAX_SERVICE)
455 {
456 if (!netif_running(dev)) {
457 printk(KERN_WARNING "%s: interrupt from stopped card\n", dev->name);
458
459 outb_p(interrupts, e8390_base + EN0_ISR);
460 interrupts = 0;
461 break;
462 }
463 if (interrupts & ENISR_OVER)
464 ei_rx_overrun(dev);
465 else if (interrupts & (ENISR_RX+ENISR_RX_ERR))
466 {
467
468 ei_receive(dev);
469 }
470
471 if (interrupts & ENISR_TX)
472 ei_tx_intr(dev);
473 else if (interrupts & ENISR_TX_ERR)
474 ei_tx_err(dev);
475
476 if (interrupts & ENISR_COUNTERS)
477 {
478 ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
479 ei_local->stat.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1);
480 ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
481 outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR);
482 }
483
484
485 if (interrupts & ENISR_RDC)
486 {
487 outb_p(ENISR_RDC, e8390_base + EN0_ISR);
488 }
489
490 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
491 }
492
493 if (interrupts && ei_debug)
494 {
495 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
496 if (nr_serviced >= MAX_SERVICE)
497 {
498
499 if(interrupts!=0xFF)
500 printk(KERN_WARNING "%s: Too much work at interrupt, status %#2.2x\n",
501 dev->name, interrupts);
502 outb_p(ENISR_ALL, e8390_base + EN0_ISR);
503 } else {
504 printk(KERN_WARNING "%s: unknown interrupt %#2x\n", dev->name, interrupts);
505 outb_p(0xff, e8390_base + EN0_ISR);
506 }
507 }
508 spin_unlock(&ei_local->page_lock);
509 return;
510}
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526static void ei_tx_err(struct net_device *dev)
527{
528 long e8390_base = dev->base_addr;
529 struct ei_device *ei_local = (struct ei_device *) dev->priv;
530 unsigned char txsr = inb_p(e8390_base+EN0_TSR);
531 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
532
533#ifdef VERBOSE_ERROR_DUMP
534 printk(KERN_DEBUG "%s: transmitter error (%#2x): ", dev->name, txsr);
535 if (txsr & ENTSR_ABT)
536 printk("excess-collisions ");
537 if (txsr & ENTSR_ND)
538 printk("non-deferral ");
539 if (txsr & ENTSR_CRS)
540 printk("lost-carrier ");
541 if (txsr & ENTSR_FU)
542 printk("FIFO-underrun ");
543 if (txsr & ENTSR_CDH)
544 printk("lost-heartbeat ");
545 printk("\n");
546#endif
547
548 outb_p(ENISR_TX_ERR, e8390_base + EN0_ISR);
549
550 if (tx_was_aborted)
551 ei_tx_intr(dev);
552 else
553 {
554 ei_local->stat.tx_errors++;
555 if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++;
556 if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++;
557 if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++;
558 }
559}
560
561
562
563
564
565
566
567
568
569static void ei_tx_intr(struct net_device *dev)
570{
571 long e8390_base = dev->base_addr;
572 struct ei_device *ei_local = (struct ei_device *) dev->priv;
573 int status = inb(e8390_base + EN0_TSR);
574
575 outb_p(ENISR_TX, e8390_base + EN0_ISR);
576
577#ifdef EI_PINGPONG
578
579
580
581
582
583 ei_local->txqueue--;
584
585 if (ei_local->tx1 < 0)
586 {
587 if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
588 printk(KERN_ERR "%s: bogus last_tx_buffer %d, tx1=%d.\n",
589 ei_local->name, ei_local->lasttx, ei_local->tx1);
590 ei_local->tx1 = 0;
591 if (ei_local->tx2 > 0)
592 {
593 ei_local->txing = 1;
594 NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
595 dev->trans_start = jiffies;
596 ei_local->tx2 = -1,
597 ei_local->lasttx = 2;
598 }
599 else ei_local->lasttx = 20, ei_local->txing = 0;
600 }
601 else if (ei_local->tx2 < 0)
602 {
603 if (ei_local->lasttx != 2 && ei_local->lasttx != -2)
604 printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
605 ei_local->name, ei_local->lasttx, ei_local->tx2);
606 ei_local->tx2 = 0;
607 if (ei_local->tx1 > 0)
608 {
609 ei_local->txing = 1;
610 NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
611 dev->trans_start = jiffies;
612 ei_local->tx1 = -1;
613 ei_local->lasttx = 1;
614 }
615 else
616 ei_local->lasttx = 10, ei_local->txing = 0;
617 }
618
619
620
621#else
622
623
624
625 ei_local->txing = 0;
626#endif
627
628
629 if (status & ENTSR_COL)
630 ei_local->stat.collisions++;
631 if (status & ENTSR_PTX)
632 ei_local->stat.tx_packets++;
633 else
634 {
635 ei_local->stat.tx_errors++;
636 if (status & ENTSR_ABT)
637 {
638 ei_local->stat.tx_aborted_errors++;
639 ei_local->stat.collisions += 16;
640 }
641 if (status & ENTSR_CRS)
642 ei_local->stat.tx_carrier_errors++;
643 if (status & ENTSR_FU)
644 ei_local->stat.tx_fifo_errors++;
645 if (status & ENTSR_CDH)
646 ei_local->stat.tx_heartbeat_errors++;
647 if (status & ENTSR_OWC)
648 ei_local->stat.tx_window_errors++;
649 }
650 netif_wake_queue(dev);
651}
652
653
654
655
656
657
658
659
660
661static void ei_receive(struct net_device *dev)
662{
663 long e8390_base = dev->base_addr;
664 struct ei_device *ei_local = (struct ei_device *) dev->priv;
665 unsigned char rxing_page, this_frame, next_frame;
666 unsigned short current_offset;
667 int rx_pkt_count = 0;
668 struct e8390_pkt_hdr rx_frame;
669 int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page;
670
671 while (++rx_pkt_count < 10)
672 {
673 int pkt_len, pkt_stat;
674
675
676 outb_p(E8390_NODMA+E8390_PAGE1, e8390_base + E8390_CMD);
677 rxing_page = inb_p(e8390_base + EN1_CURPAG);
678 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
679
680
681 this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
682 if (this_frame >= ei_local->stop_page)
683 this_frame = ei_local->rx_start_page;
684
685
686
687
688
689
690
691 if (ei_debug > 0 && this_frame != ei_local->current_page && (this_frame!=0x0 || rxing_page!=0xFF))
692 printk(KERN_ERR "%s: mismatched read page pointers %2x vs %2x.\n",
693 dev->name, this_frame, ei_local->current_page);
694
695 if (this_frame == rxing_page)
696 break;
697
698 current_offset = this_frame << 8;
699 ei_get_8390_hdr(dev, &rx_frame, this_frame);
700
701 pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr);
702 pkt_stat = rx_frame.status;
703
704 next_frame = this_frame + 1 + ((pkt_len+4)>>8);
705
706
707
708
709 if (rx_frame.next != next_frame
710 && rx_frame.next != next_frame + 1
711 && rx_frame.next != next_frame - num_rx_pages
712 && rx_frame.next != next_frame + 1 - num_rx_pages) {
713 ei_local->current_page = rxing_page;
714 outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
715 ei_local->stat.rx_errors++;
716 continue;
717 }
718
719 if (pkt_len < 60 || pkt_len > 1518)
720 {
721 if (ei_debug)
722 printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
723 dev->name, rx_frame.count, rx_frame.status,
724 rx_frame.next);
725 ei_local->stat.rx_errors++;
726 ei_local->stat.rx_length_errors++;
727 }
728 else if ((pkt_stat & 0x0F) == ENRSR_RXOK)
729 {
730 struct sk_buff *skb;
731
732 skb = dev_alloc_skb(pkt_len+2);
733 if (skb == NULL)
734 {
735 if (ei_debug > 1)
736 printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n",
737 dev->name, pkt_len);
738 ei_local->stat.rx_dropped++;
739 break;
740 }
741 else
742 {
743 skb_reserve(skb,2);
744 skb->dev = dev;
745 skb_put(skb, pkt_len);
746 ei_block_input(dev, pkt_len, skb, current_offset + sizeof(rx_frame));
747 skb->protocol=eth_type_trans(skb,dev);
748 netif_rx(skb);
749 dev->last_rx = jiffies;
750 ei_local->stat.rx_packets++;
751 ei_local->stat.rx_bytes += pkt_len;
752 if (pkt_stat & ENRSR_PHY)
753 ei_local->stat.multicast++;
754 }
755 }
756 else
757 {
758 if (ei_debug)
759 printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
760 dev->name, rx_frame.status, rx_frame.next,
761 rx_frame.count);
762 ei_local->stat.rx_errors++;
763
764 if (pkt_stat & ENRSR_FO)
765 ei_local->stat.rx_fifo_errors++;
766 }
767 next_frame = rx_frame.next;
768
769
770 if (next_frame >= ei_local->stop_page) {
771 printk("%s: next frame inconsistency, %#2x\n", dev->name,
772 next_frame);
773 next_frame = ei_local->rx_start_page;
774 }
775 ei_local->current_page = next_frame;
776 outb_p(next_frame-1, e8390_base+EN0_BOUNDARY);
777 }
778
779
780
781 outb_p(ENISR_RX+ENISR_RX_ERR, e8390_base+EN0_ISR);
782 return;
783}
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798static void ei_rx_overrun(struct net_device *dev)
799{
800 long e8390_base = dev->base_addr;
801 unsigned char was_txing, must_resend = 0;
802 struct ei_device *ei_local = (struct ei_device *) dev->priv;
803
804
805
806
807
808 was_txing = inb_p(e8390_base+E8390_CMD) & E8390_TRANS;
809 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
810
811 if (ei_debug > 1)
812 printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name);
813 ei_local->stat.rx_over_errors++;
814
815
816
817
818
819
820
821
822 udelay(10*1000);
823
824
825
826
827 outb_p(0x00, e8390_base+EN0_RCNTLO);
828 outb_p(0x00, e8390_base+EN0_RCNTHI);
829
830
831
832
833
834
835 if (was_txing)
836 {
837 unsigned char tx_completed = inb_p(e8390_base+EN0_ISR) & (ENISR_TX+ENISR_TX_ERR);
838 if (!tx_completed)
839 must_resend = 1;
840 }
841
842
843
844
845
846 outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
847 outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
848
849
850
851
852 ei_receive(dev);
853 outb_p(ENISR_OVER, e8390_base+EN0_ISR);
854
855
856
857
858 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR);
859 if (must_resend)
860 outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START + E8390_TRANS, e8390_base + E8390_CMD);
861}
862
863
864
865
866
867static struct net_device_stats *get_stats(struct net_device *dev)
868{
869 long ioaddr = dev->base_addr;
870 struct ei_device *ei_local = (struct ei_device *) dev->priv;
871 unsigned long flags;
872
873
874 if (!netif_running(dev))
875 return &ei_local->stat;
876
877 spin_lock_irqsave(&ei_local->page_lock,flags);
878
879 ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
880 ei_local->stat.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1);
881 ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
882 spin_unlock_irqrestore(&ei_local->page_lock, flags);
883
884 return &ei_local->stat;
885}
886
887
888
889
890
891
892static inline void make_mc_bits(u8 *bits, struct net_device *dev)
893{
894 struct dev_mc_list *dmi;
895
896 for (dmi=dev->mc_list; dmi; dmi=dmi->next)
897 {
898 u32 crc;
899 if (dmi->dmi_addrlen != ETH_ALEN)
900 {
901 printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
902 continue;
903 }
904 crc = ether_crc(ETH_ALEN, dmi->dmi_addr);
905
906
907
908
909 bits[crc>>29] |= (1<<((crc>>26)&7));
910 }
911}
912
913
914
915
916
917
918
919
920
921static void do_set_multicast_list(struct net_device *dev)
922{
923 long e8390_base = dev->base_addr;
924 int i;
925 struct ei_device *ei_local = (struct ei_device*)dev->priv;
926
927 if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI)))
928 {
929 memset(ei_local->mcfilter, 0, 8);
930 if (dev->mc_list)
931 make_mc_bits(ei_local->mcfilter, dev);
932 }
933 else
934 memset(ei_local->mcfilter, 0xFF, 8);
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949 if (netif_running(dev))
950 outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
951 outb_p(E8390_NODMA + E8390_PAGE1, e8390_base + E8390_CMD);
952 for(i = 0; i < 8; i++)
953 {
954 outb_p(ei_local->mcfilter[i], e8390_base + EN1_MULT_SHIFT(i));
955#ifndef BUG_83C690
956 if(inb_p(e8390_base + EN1_MULT_SHIFT(i))!=ei_local->mcfilter[i])
957 printk(KERN_ERR "Multicast filter read/write mismap %d\n",i);
958#endif
959 }
960 outb_p(E8390_NODMA + E8390_PAGE0, e8390_base + E8390_CMD);
961
962 if(dev->flags&IFF_PROMISC)
963 outb_p(E8390_RXCONFIG | 0x18, e8390_base + EN0_RXCR);
964 else if(dev->flags&IFF_ALLMULTI || dev->mc_list)
965 outb_p(E8390_RXCONFIG | 0x08, e8390_base + EN0_RXCR);
966 else
967 outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
968 }
969
970
971
972
973
974
975
976static void set_multicast_list(struct net_device *dev)
977{
978 unsigned long flags;
979 struct ei_device *ei_local = (struct ei_device*)dev->priv;
980
981 spin_lock_irqsave(&ei_local->page_lock, flags);
982 do_set_multicast_list(dev);
983 spin_unlock_irqrestore(&ei_local->page_lock, flags);
984}
985
986
987
988
989
990
991
992
993
994int ethdev_init(struct net_device *dev)
995{
996 if (ei_debug > 1)
997 printk(version);
998
999 if (dev->priv == NULL)
1000 {
1001 struct ei_device *ei_local;
1002
1003 dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
1004 if (dev->priv == NULL)
1005 return -ENOMEM;
1006 memset(dev->priv, 0, sizeof(struct ei_device));
1007 ei_local = (struct ei_device *)dev->priv;
1008 spin_lock_init(&ei_local->page_lock);
1009 }
1010
1011 dev->hard_start_xmit = &ei_start_xmit;
1012 dev->get_stats = get_stats;
1013 dev->set_multicast_list = &set_multicast_list;
1014
1015 ether_setup(dev);
1016
1017 return 0;
1018}
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033void NS8390_init(struct net_device *dev, int startp)
1034{
1035 long e8390_base = dev->base_addr;
1036 struct ei_device *ei_local = (struct ei_device *) dev->priv;
1037 int i;
1038 int endcfg = ei_local->word16
1039 ? (0x48 | ENDCFG_WTS | (ei_local->bigendian ? ENDCFG_BOS : 0))
1040 : 0x48;
1041
1042 if(sizeof(struct e8390_pkt_hdr)!=4)
1043 panic("8390.c: header struct mispacked\n");
1044
1045 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
1046 outb_p(endcfg, e8390_base + EN0_DCFG);
1047
1048 outb_p(0x00, e8390_base + EN0_RCNTLO);
1049 outb_p(0x00, e8390_base + EN0_RCNTHI);
1050
1051 outb_p(E8390_RXOFF, e8390_base + EN0_RXCR);
1052 outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
1053
1054 outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
1055 ei_local->tx1 = ei_local->tx2 = 0;
1056 outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
1057 outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY);
1058 ei_local->current_page = ei_local->rx_start_page;
1059 outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
1060
1061 outb_p(0xFF, e8390_base + EN0_ISR);
1062 outb_p(0x00, e8390_base + EN0_IMR);
1063
1064
1065
1066 outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base+E8390_CMD);
1067 for(i = 0; i < 6; i++)
1068 {
1069 outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i));
1070 if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i])
1071 printk(KERN_ERR "Hw. address read/write mismap %d\n",i);
1072 }
1073
1074 outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
1075 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
1076
1077 netif_start_queue(dev);
1078 ei_local->tx1 = ei_local->tx2 = 0;
1079 ei_local->txing = 0;
1080
1081 if (startp)
1082 {
1083 outb_p(0xff, e8390_base + EN0_ISR);
1084 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
1085 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
1086 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR);
1087
1088 outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
1089 do_set_multicast_list(dev);
1090 }
1091}
1092
1093
1094
1095
1096static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
1097 int start_page)
1098{
1099 long e8390_base = dev->base_addr;
1100 struct ei_device *ei_local __attribute((unused)) = (struct ei_device *) dev->priv;
1101
1102 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base+E8390_CMD);
1103
1104 if (inb_p(e8390_base) & E8390_TRANS)
1105 {
1106 printk(KERN_WARNING "%s: trigger_send() called with the transmitter busy.\n",
1107 dev->name);
1108 return;
1109 }
1110 outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
1111 outb_p(length >> 8, e8390_base + EN0_TCNTHI);
1112 outb_p(start_page, e8390_base + EN0_TPSR);
1113 outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base+E8390_CMD);
1114}
1115
1116EXPORT_SYMBOL(ei_open);
1117EXPORT_SYMBOL(ei_close);
1118EXPORT_SYMBOL(ei_interrupt);
1119EXPORT_SYMBOL(ei_tx_timeout);
1120EXPORT_SYMBOL(ethdev_init);
1121EXPORT_SYMBOL(NS8390_init);
1122
1123#if defined(MODULE)
1124
1125int init_module(void)
1126{
1127 return 0;
1128}
1129
1130void cleanup_module(void)
1131{
1132}
1133
1134#endif
1135MODULE_LICENSE("GPL");
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147