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#define DRV_NAME "3c505"
42#define DRV_VERSION "1.10a"
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99#include <linux/module.h>
100
101#include <linux/kernel.h>
102#include <linux/sched.h>
103#include <linux/string.h>
104#include <linux/interrupt.h>
105#include <linux/errno.h>
106#include <linux/in.h>
107#include <linux/slab.h>
108#include <linux/ioport.h>
109#include <linux/spinlock.h>
110#include <linux/ethtool.h>
111
112#include <asm/uaccess.h>
113#include <asm/bitops.h>
114#include <asm/io.h>
115#include <asm/dma.h>
116
117#include <linux/netdevice.h>
118#include <linux/etherdevice.h>
119#include <linux/skbuff.h>
120#include <linux/init.h>
121
122#include "3c505.h"
123
124
125
126
127
128
129
130static const char filename[] = __FILE__;
131
132static const char timeout_msg[] = "*** timeout at %s:%s (line %d) ***\n";
133#define TIMEOUT_MSG(lineno) \
134 printk(timeout_msg, filename,__FUNCTION__,(lineno))
135
136static const char invalid_pcb_msg[] =
137"*** invalid pcb length %d at %s:%s (line %d) ***\n";
138#define INVALID_PCB_MSG(len) \
139 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
140
141static char search_msg[] __initdata = "%s: Looking for 3c505 adapter at address %#x...";
142
143static char stilllooking_msg[] __initdata = "still looking...";
144
145static char found_msg[] __initdata = "found.\n";
146
147static char notfound_msg[] __initdata = "not found (reason = %d)\n";
148
149static char couldnot_msg[] __initdata = "%s: 3c505 not found\n";
150
151
152
153
154
155
156
157#ifdef ELP_DEBUG
158static int elp_debug = ELP_DEBUG;
159#else
160static int elp_debug;
161#endif
162#define debug elp_debug
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177#ifndef TRUE
178#define TRUE 1
179#endif
180
181#ifndef FALSE
182#define FALSE 0
183#endif
184
185
186
187
188
189
190
191
192static int addr_list[] __initdata = {0x300, 0x280, 0x310, 0};
193
194
195
196static unsigned long dma_mem_alloc(int size)
197{
198 int order = get_order(size);
199
200 return __get_dma_pages(GFP_KERNEL, order);
201}
202
203
204
205
206
207
208
209
210static inline unsigned char inb_status(unsigned int base_addr)
211{
212 return inb(base_addr + PORT_STATUS);
213}
214
215static inline int inb_command(unsigned int base_addr)
216{
217 return inb(base_addr + PORT_COMMAND);
218}
219
220static inline void outb_control(unsigned char val, struct net_device *dev)
221{
222 outb(val, dev->base_addr + PORT_CONTROL);
223 ((elp_device *)(dev->priv))->hcr_val = val;
224}
225
226#define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val)
227
228static inline void outb_command(unsigned char val, unsigned int base_addr)
229{
230 outb(val, base_addr + PORT_COMMAND);
231}
232
233static inline unsigned int inw_data(unsigned int base_addr)
234{
235 return inw(base_addr + PORT_DATA);
236}
237
238static inline void outw_data(unsigned int val, unsigned int base_addr)
239{
240 outw(val, base_addr + PORT_DATA);
241}
242
243static inline unsigned int backlog_next(unsigned int n)
244{
245 return (n + 1) % BACKLOG_SIZE;
246}
247
248
249
250
251
252
253
254
255
256
257
258
259
260#define GET_ASF(addr) \
261 (get_status(addr)&ASF_PCB_MASK)
262
263static inline int get_status(unsigned int base_addr)
264{
265 int timeout = jiffies + 10*HZ/100;
266 register int stat1;
267 do {
268 stat1 = inb_status(base_addr);
269 } while (stat1 != inb_status(base_addr) && time_before(jiffies, timeout));
270 if (time_after_eq(jiffies, timeout))
271 TIMEOUT_MSG(__LINE__);
272 return stat1;
273}
274
275static inline void set_hsf(struct net_device *dev, int hsf)
276{
277 cli();
278 outb_control((HCR_VAL(dev) & ~HSF_PCB_MASK) | hsf, dev);
279 sti();
280}
281
282static int start_receive(struct net_device *, pcb_struct *);
283
284inline static void adapter_reset(struct net_device *dev)
285{
286 int timeout;
287 elp_device *adapter = dev->priv;
288 unsigned char orig_hcr = adapter->hcr_val;
289
290 outb_control(0, dev);
291
292 if (inb_status(dev->base_addr) & ACRF) {
293 do {
294 inb_command(dev->base_addr);
295 timeout = jiffies + 2*HZ/100;
296 while (time_before_eq(jiffies, timeout) && !(inb_status(dev->base_addr) & ACRF));
297 } while (inb_status(dev->base_addr) & ACRF);
298 set_hsf(dev, HSF_PCB_NAK);
299 }
300 outb_control(adapter->hcr_val | ATTN | DIR, dev);
301 timeout = jiffies + 1*HZ/100;
302 while (time_before_eq(jiffies, timeout));
303 outb_control(adapter->hcr_val & ~ATTN, dev);
304 timeout = jiffies + 1*HZ/100;
305 while (time_before_eq(jiffies, timeout));
306 outb_control(adapter->hcr_val | FLSH, dev);
307 timeout = jiffies + 1*HZ/100;
308 while (time_before_eq(jiffies, timeout));
309 outb_control(adapter->hcr_val & ~FLSH, dev);
310 timeout = jiffies + 1*HZ/100;
311 while (time_before_eq(jiffies, timeout));
312
313 outb_control(orig_hcr, dev);
314 if (!start_receive(dev, &adapter->tx_pcb))
315 printk("%s: start receive command failed \n", dev->name);
316}
317
318
319
320
321
322static inline void check_3c505_dma(struct net_device *dev)
323{
324 elp_device *adapter = dev->priv;
325 if (adapter->dmaing && time_after(jiffies, adapter->current_dma.start_time + 10)) {
326 unsigned long flags, f;
327 printk("%s: DMA %s timed out, %d bytes left\n", dev->name, adapter->current_dma.direction ? "download" : "upload", get_dma_residue(dev->dma));
328 save_flags(flags);
329 cli();
330 adapter->dmaing = 0;
331 adapter->busy = 0;
332
333 f=claim_dma_lock();
334 disable_dma(dev->dma);
335 release_dma_lock(f);
336
337 if (adapter->rx_active)
338 adapter->rx_active--;
339 outb_control(adapter->hcr_val & ~(DMAE | TCEN | DIR), dev);
340 restore_flags(flags);
341 }
342}
343
344
345static inline unsigned int send_pcb_slow(unsigned int base_addr, unsigned char byte)
346{
347 unsigned int timeout;
348 outb_command(byte, base_addr);
349 for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) {
350 if (inb_status(base_addr) & HCRE)
351 return FALSE;
352 }
353 printk("3c505: send_pcb_slow timed out\n");
354 return TRUE;
355}
356
357static inline unsigned int send_pcb_fast(unsigned int base_addr, unsigned char byte)
358{
359 unsigned int timeout;
360 outb_command(byte, base_addr);
361 for (timeout = 0; timeout < 40000; timeout++) {
362 if (inb_status(base_addr) & HCRE)
363 return FALSE;
364 }
365 printk("3c505: send_pcb_fast timed out\n");
366 return TRUE;
367}
368
369
370static inline void prime_rx(struct net_device *dev)
371{
372 elp_device *adapter = dev->priv;
373 while (adapter->rx_active < ELP_RX_PCBS && netif_running(dev)) {
374 if (!start_receive(dev, &adapter->itx_pcb))
375 break;
376 }
377}
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403static int send_pcb(struct net_device *dev, pcb_struct * pcb)
404{
405 int i;
406 int timeout;
407 elp_device *adapter = dev->priv;
408
409 check_3c505_dma(dev);
410
411 if (adapter->dmaing && adapter->current_dma.direction == 0)
412 return FALSE;
413
414
415 if (test_and_set_bit(1, &adapter->send_pcb_semaphore)) {
416 if (elp_debug >= 3) {
417 printk("%s: send_pcb entered while threaded\n", dev->name);
418 }
419 return FALSE;
420 }
421
422
423
424
425
426 set_hsf(dev, 0);
427
428 if (send_pcb_slow(dev->base_addr, pcb->command))
429 goto abort;
430
431 cli();
432
433 if (send_pcb_fast(dev->base_addr, pcb->length))
434 goto sti_abort;
435
436 for (i = 0; i < pcb->length; i++) {
437 if (send_pcb_fast(dev->base_addr, pcb->data.raw[i]))
438 goto sti_abort;
439 }
440
441 outb_control(adapter->hcr_val | 3, dev);
442 outb_command(2 + pcb->length, dev->base_addr);
443
444
445 sti();
446
447 for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) {
448 switch (GET_ASF(dev->base_addr)) {
449 case ASF_PCB_ACK:
450 adapter->send_pcb_semaphore = 0;
451 return TRUE;
452 break;
453 case ASF_PCB_NAK:
454#ifdef ELP_DEBUG
455 printk(KERN_DEBUG "%s: send_pcb got NAK\n", dev->name);
456#endif
457 goto abort;
458 break;
459 }
460 }
461
462 if (elp_debug >= 1)
463 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev->name, inb_status(dev->base_addr));
464
465 sti_abort:
466 sti();
467 abort:
468 adapter->send_pcb_semaphore = 0;
469 return FALSE;
470}
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
487{
488 int i, j;
489 int total_length;
490 int stat;
491 int timeout;
492
493 elp_device *adapter = dev->priv;
494
495 set_hsf(dev, 0);
496
497
498 timeout = jiffies + 2*HZ/100;
499 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout));
500 if (time_after_eq(jiffies, timeout)) {
501 TIMEOUT_MSG(__LINE__);
502 return FALSE;
503 }
504 pcb->command = inb_command(dev->base_addr);
505
506
507 timeout = jiffies + 3*HZ/100;
508 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout));
509 if (time_after_eq(jiffies, timeout)) {
510 TIMEOUT_MSG(__LINE__);
511 printk("%s: status %02x\n", dev->name, stat);
512 return FALSE;
513 }
514 pcb->length = inb_command(dev->base_addr);
515
516 if (pcb->length > MAX_PCB_DATA) {
517 INVALID_PCB_MSG(pcb->length);
518 adapter_reset(dev);
519 return FALSE;
520 }
521
522 cli();
523 i = 0;
524 do {
525 j = 0;
526 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
527 pcb->data.raw[i++] = inb_command(dev->base_addr);
528 if (i > MAX_PCB_DATA)
529 INVALID_PCB_MSG(i);
530 } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
531 sti();
532 if (j >= 20000) {
533 TIMEOUT_MSG(__LINE__);
534 return FALSE;
535 }
536
537 total_length = pcb->data.raw[--i];
538
539
540 if (total_length != (pcb->length + 2)) {
541 if (elp_debug >= 2)
542 printk("%s: mangled PCB received\n", dev->name);
543 set_hsf(dev, HSF_PCB_NAK);
544 return FALSE;
545 }
546
547 if (pcb->command == CMD_RECEIVE_PACKET_COMPLETE) {
548 if (test_and_set_bit(0, (void *) &adapter->busy)) {
549 if (backlog_next(adapter->rx_backlog.in) == adapter->rx_backlog.out) {
550 set_hsf(dev, HSF_PCB_NAK);
551 printk("%s: PCB rejected, transfer in progress and backlog full\n", dev->name);
552 pcb->command = 0;
553 return TRUE;
554 } else {
555 pcb->command = 0xff;
556 }
557 }
558 }
559 set_hsf(dev, HSF_PCB_ACK);
560 return TRUE;
561}
562
563
564
565
566
567
568
569
570static int start_receive(struct net_device *dev, pcb_struct * tx_pcb)
571{
572 int status;
573 elp_device *adapter = dev->priv;
574
575 if (elp_debug >= 3)
576 printk("%s: restarting receiver\n", dev->name);
577 tx_pcb->command = CMD_RECEIVE_PACKET;
578 tx_pcb->length = sizeof(struct Rcv_pkt);
579 tx_pcb->data.rcv_pkt.buf_seg
580 = tx_pcb->data.rcv_pkt.buf_ofs = 0;
581 tx_pcb->data.rcv_pkt.buf_len = 1600;
582 tx_pcb->data.rcv_pkt.timeout = 0;
583 status = send_pcb(dev, tx_pcb);
584 if (status)
585 adapter->rx_active++;
586 return status;
587}
588
589
590
591
592
593
594
595
596
597
598static void receive_packet(struct net_device *dev, int len)
599{
600 int rlen;
601 elp_device *adapter = dev->priv;
602 void *target;
603 struct sk_buff *skb;
604 unsigned long flags;
605
606 rlen = (len + 1) & ~1;
607 skb = dev_alloc_skb(rlen + 2);
608
609 if (!skb) {
610 printk("%s: memory squeeze, dropping packet\n", dev->name);
611 target = adapter->dma_buffer;
612 adapter->current_dma.target = NULL;
613 return;
614 }
615
616 skb_reserve(skb, 2);
617 target = skb_put(skb, rlen);
618 if ((unsigned long)(target + rlen) >= MAX_DMA_ADDRESS) {
619 adapter->current_dma.target = target;
620 target = adapter->dma_buffer;
621 } else {
622 adapter->current_dma.target = NULL;
623 }
624
625
626 if (test_and_set_bit(0, (void *) &adapter->dmaing))
627 printk("%s: rx blocked, DMA in progress, dir %d\n", dev->name, adapter->current_dma.direction);
628
629 skb->dev = dev;
630 adapter->current_dma.direction = 0;
631 adapter->current_dma.length = rlen;
632 adapter->current_dma.skb = skb;
633 adapter->current_dma.start_time = jiffies;
634
635 outb_control(adapter->hcr_val | DIR | TCEN | DMAE, dev);
636
637 flags=claim_dma_lock();
638 disable_dma(dev->dma);
639 clear_dma_ff(dev->dma);
640 set_dma_mode(dev->dma, 0x04);
641 set_dma_addr(dev->dma, isa_virt_to_bus(target));
642 set_dma_count(dev->dma, rlen);
643 enable_dma(dev->dma);
644 release_dma_lock(flags);
645
646 if (elp_debug >= 3) {
647 printk("%s: rx DMA transfer started\n", dev->name);
648 }
649
650 if (adapter->rx_active)
651 adapter->rx_active--;
652
653 if (!adapter->busy)
654 printk("%s: receive_packet called, busy not set.\n", dev->name);
655}
656
657
658
659
660
661
662
663static void elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
664{
665 int len;
666 int dlen;
667 int icount = 0;
668 struct net_device *dev;
669 elp_device *adapter;
670 int timeout;
671
672 dev = dev_id;
673 adapter = (elp_device *) dev->priv;
674
675 spin_lock(&adapter->lock);
676
677 do {
678
679
680
681 if (inb_status(dev->base_addr) & DONE) {
682 if (!adapter->dmaing) {
683 printk("%s: phantom DMA completed\n", dev->name);
684 }
685 if (elp_debug >= 3) {
686 printk("%s: %s DMA complete, status %02x\n", dev->name, adapter->current_dma.direction ? "tx" : "rx", inb_status(dev->base_addr));
687 }
688
689 outb_control(adapter->hcr_val & ~(DMAE | TCEN | DIR), dev);
690 if (adapter->current_dma.direction) {
691 dev_kfree_skb_irq(adapter->current_dma.skb);
692 } else {
693 struct sk_buff *skb = adapter->current_dma.skb;
694 if (skb) {
695 if (adapter->current_dma.target) {
696
697 memcpy(adapter->current_dma.target, adapter->dma_buffer, adapter->current_dma.length);
698 }
699 skb->protocol = eth_type_trans(skb,dev);
700 adapter->stats.rx_bytes += skb->len;
701 netif_rx(skb);
702 dev->last_rx = jiffies;
703 }
704 }
705 adapter->dmaing = 0;
706 if (adapter->rx_backlog.in != adapter->rx_backlog.out) {
707 int t = adapter->rx_backlog.length[adapter->rx_backlog.out];
708 adapter->rx_backlog.out = backlog_next(adapter->rx_backlog.out);
709 if (elp_debug >= 2)
710 printk("%s: receiving backlogged packet (%d)\n", dev->name, t);
711 receive_packet(dev, t);
712 } else {
713 adapter->busy = 0;
714 }
715 } else {
716
717 check_3c505_dma(dev);
718 }
719
720
721
722
723 timeout = jiffies + 3*HZ/100;
724 while ((inb_status(dev->base_addr) & ACRF) != 0 && time_before(jiffies, timeout)) {
725 if (receive_pcb(dev, &adapter->irx_pcb)) {
726 switch (adapter->irx_pcb.command)
727 {
728 case 0:
729 break;
730
731
732
733 case 0xff:
734 case CMD_RECEIVE_PACKET_COMPLETE:
735
736 if (!netif_running(dev))
737 break;
738 len = adapter->irx_pcb.data.rcv_resp.pkt_len;
739 dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
740 if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
741 printk(KERN_ERR "%s: interrupt - packet not received correctly\n", dev->name);
742 } else {
743 if (elp_debug >= 3) {
744 printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
745 }
746 if (adapter->irx_pcb.command == 0xff) {
747 if (elp_debug >= 2)
748 printk("%s: adding packet to backlog (len = %d)\n", dev->name, dlen);
749 adapter->rx_backlog.length[adapter->rx_backlog.in] = dlen;
750 adapter->rx_backlog.in = backlog_next(adapter->rx_backlog.in);
751 } else {
752 receive_packet(dev, dlen);
753 }
754 if (elp_debug >= 3)
755 printk("%s: packet received\n", dev->name);
756 }
757 break;
758
759
760
761
762 case CMD_CONFIGURE_82586_RESPONSE:
763 adapter->got[CMD_CONFIGURE_82586] = 1;
764 if (elp_debug >= 3)
765 printk("%s: interrupt - configure response received\n", dev->name);
766 break;
767
768
769
770
771 case CMD_CONFIGURE_ADAPTER_RESPONSE:
772 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
773 if (elp_debug >= 3)
774 printk("%s: Adapter memory configuration %s.\n", dev->name,
775 adapter->irx_pcb.data.failed ? "failed" : "succeeded");
776 break;
777
778
779
780
781 case CMD_LOAD_MULTICAST_RESPONSE:
782 adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
783 if (elp_debug >= 3)
784 printk("%s: Multicast address list loading %s.\n", dev->name,
785 adapter->irx_pcb.data.failed ? "failed" : "succeeded");
786 break;
787
788
789
790
791 case CMD_SET_ADDRESS_RESPONSE:
792 adapter->got[CMD_SET_STATION_ADDRESS] = 1;
793 if (elp_debug >= 3)
794 printk("%s: Ethernet address setting %s.\n", dev->name,
795 adapter->irx_pcb.data.failed ? "failed" : "succeeded");
796 break;
797
798
799
800
801
802 case CMD_NETWORK_STATISTICS_RESPONSE:
803 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
804 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
805 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
806 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
807 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
808 adapter->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res;
809 adapter->got[CMD_NETWORK_STATISTICS] = 1;
810 if (elp_debug >= 3)
811 printk("%s: interrupt - statistics response received\n", dev->name);
812 break;
813
814
815
816
817 case CMD_TRANSMIT_PACKET_COMPLETE:
818 if (elp_debug >= 3)
819 printk("%s: interrupt - packet sent\n", dev->name);
820 if (!netif_running(dev))
821 break;
822 switch (adapter->irx_pcb.data.xmit_resp.c_stat) {
823 case 0xffff:
824 adapter->stats.tx_aborted_errors++;
825 printk(KERN_INFO "%s: transmit timed out, network cable problem?\n", dev->name);
826 break;
827 case 0xfffe:
828 adapter->stats.tx_fifo_errors++;
829 printk(KERN_INFO "%s: transmit timed out, FIFO underrun\n", dev->name);
830 break;
831 }
832 netif_wake_queue(dev);
833 break;
834
835
836
837
838 default:
839 printk(KERN_DEBUG "%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
840 break;
841 }
842 } else {
843 printk("%s: failed to read PCB on interrupt\n", dev->name);
844 adapter_reset(dev);
845 }
846 }
847
848 } while (icount++ < 5 && (inb_status(dev->base_addr) & (ACRF | DONE)));
849
850 prime_rx(dev);
851
852
853
854
855 spin_unlock(&adapter->lock);
856}
857
858
859
860
861
862
863
864
865static int elp_open(struct net_device *dev)
866{
867 elp_device *adapter;
868 int retval;
869
870 adapter = dev->priv;
871
872 if (elp_debug >= 3)
873 printk("%s: request to open device\n", dev->name);
874
875
876
877
878 if (adapter == NULL) {
879 printk("%s: Opening a non-existent physical device\n", dev->name);
880 return -EAGAIN;
881 }
882
883
884
885 outb_control(0, dev);
886
887
888
889
890 inb_command(dev->base_addr);
891 adapter_reset(dev);
892
893
894
895
896 adapter->rx_active = 0;
897
898 adapter->busy = 0;
899 adapter->send_pcb_semaphore = 0;
900 adapter->rx_backlog.in = 0;
901 adapter->rx_backlog.out = 0;
902
903 spin_lock_init(&adapter->lock);
904
905
906
907
908 if ((retval = request_irq(dev->irq, &elp_interrupt, 0, dev->name, dev))) {
909 printk(KERN_ERR "%s: could not allocate IRQ%d\n", dev->name, dev->irq);
910 return retval;
911 }
912 if ((retval = request_dma(dev->dma, dev->name))) {
913 free_irq(dev->irq, dev);
914 printk(KERN_ERR "%s: could not allocate DMA%d channel\n", dev->name, dev->dma);
915 return retval;
916 }
917 adapter->dma_buffer = (void *) dma_mem_alloc(DMA_BUFFER_SIZE);
918 if (!adapter->dma_buffer) {
919 printk(KERN_ERR "%s: could not allocate DMA buffer\n", dev->name);
920 free_dma(dev->dma);
921 free_irq(dev->irq, dev);
922 return -ENOMEM;
923 }
924 adapter->dmaing = 0;
925
926
927
928
929 outb_control(CMDE, dev);
930
931
932
933
934 if (elp_debug >= 3)
935 printk(KERN_DEBUG "%s: sending 3c505 memory configuration command\n", dev->name);
936 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
937 adapter->tx_pcb.data.memconf.cmd_q = 10;
938 adapter->tx_pcb.data.memconf.rcv_q = 20;
939 adapter->tx_pcb.data.memconf.mcast = 10;
940 adapter->tx_pcb.data.memconf.frame = 20;
941 adapter->tx_pcb.data.memconf.rcv_b = 20;
942 adapter->tx_pcb.data.memconf.progs = 0;
943 adapter->tx_pcb.length = sizeof(struct Memconf);
944 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
945 if (!send_pcb(dev, &adapter->tx_pcb))
946 printk("%s: couldn't send memory configuration command\n", dev->name);
947 else {
948 int timeout = jiffies + TIMEOUT;
949 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && time_before(jiffies, timeout));
950 if (time_after_eq(jiffies, timeout))
951 TIMEOUT_MSG(__LINE__);
952 }
953
954
955
956
957
958 if (elp_debug >= 3)
959 printk("%s: sending 82586 configure command\n", dev->name);
960 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
961 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
962 adapter->tx_pcb.length = 2;
963 adapter->got[CMD_CONFIGURE_82586] = 0;
964 if (!send_pcb(dev, &adapter->tx_pcb))
965 printk("%s: couldn't send 82586 configure command\n", dev->name);
966 else {
967 int timeout = jiffies + TIMEOUT;
968 while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout));
969 if (time_after_eq(jiffies, timeout))
970 TIMEOUT_MSG(__LINE__);
971 }
972
973
974
975
976
977
978
979 prime_rx(dev);
980 if (elp_debug >= 3)
981 printk("%s: %d receive PCBs active\n", dev->name, adapter->rx_active);
982
983
984
985
986
987 netif_start_queue(dev);
988 return 0;
989}
990
991
992
993
994
995
996
997
998static int send_packet(struct net_device *dev, struct sk_buff *skb)
999{
1000 elp_device *adapter = dev->priv;
1001 unsigned long target;
1002 unsigned long flags;
1003
1004
1005
1006
1007 unsigned int nlen = (((skb->len < 60) ? 60 : skb->len) + 1) & (~1);
1008
1009 if (test_and_set_bit(0, (void *) &adapter->busy)) {
1010 if (elp_debug >= 2)
1011 printk("%s: transmit blocked\n", dev->name);
1012 return FALSE;
1013 }
1014
1015 adapter->stats.tx_bytes += nlen;
1016
1017
1018
1019
1020
1021 adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
1022 adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
1023 adapter->tx_pcb.data.xmit_pkt.buf_ofs
1024 = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0;
1025 adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
1026
1027 if (!send_pcb(dev, &adapter->tx_pcb)) {
1028 adapter->busy = 0;
1029 return FALSE;
1030 }
1031
1032 if (test_and_set_bit(0, (void *) &adapter->dmaing))
1033 printk("%s: tx: DMA %d in progress\n", dev->name, adapter->current_dma.direction);
1034
1035 adapter->current_dma.direction = 1;
1036 adapter->current_dma.start_time = jiffies;
1037
1038 if ((unsigned long)(skb->data + nlen) >= MAX_DMA_ADDRESS) {
1039 memcpy(adapter->dma_buffer, skb->data, nlen);
1040 target = isa_virt_to_bus(adapter->dma_buffer);
1041 }
1042 else {
1043 target = isa_virt_to_bus(skb->data);
1044 }
1045 adapter->current_dma.skb = skb;
1046
1047 flags=claim_dma_lock();
1048 disable_dma(dev->dma);
1049 clear_dma_ff(dev->dma);
1050 set_dma_mode(dev->dma, 0x48);
1051 set_dma_addr(dev->dma, target);
1052 set_dma_count(dev->dma, nlen);
1053 outb_control(adapter->hcr_val | DMAE | TCEN, dev);
1054 enable_dma(dev->dma);
1055 release_dma_lock(flags);
1056
1057 if (elp_debug >= 3)
1058 printk("%s: DMA transfer started\n", dev->name);
1059
1060 return TRUE;
1061}
1062
1063
1064
1065
1066
1067static void elp_timeout(struct net_device *dev)
1068{
1069 elp_device *adapter = dev->priv;
1070 int stat;
1071
1072 stat = inb_status(dev->base_addr);
1073 printk(KERN_WARNING "%s: transmit timed out, lost %s?\n", dev->name, (stat & ACRF) ? "interrupt" : "command");
1074 if (elp_debug >= 1)
1075 printk("%s: status %#02x\n", dev->name, stat);
1076 dev->trans_start = jiffies;
1077 adapter->stats.tx_dropped++;
1078 netif_wake_queue(dev);
1079}
1080
1081
1082
1083
1084
1085
1086
1087
1088static int elp_start_xmit(struct sk_buff *skb, struct net_device *dev)
1089{
1090 unsigned long flags;
1091 elp_device *adapter = dev->priv;
1092
1093 spin_lock_irqsave(&adapter->lock, flags);
1094 check_3c505_dma(dev);
1095
1096 if (elp_debug >= 3)
1097 printk("%s: request to send packet of length %d\n", dev->name, (int) skb->len);
1098
1099 netif_stop_queue(dev);
1100
1101
1102
1103
1104 if (!send_packet(dev, skb)) {
1105 if (elp_debug >= 2) {
1106 printk("%s: failed to transmit packet\n", dev->name);
1107 }
1108 spin_unlock_irqrestore(&adapter->lock, flags);
1109 return 1;
1110 }
1111 if (elp_debug >= 3)
1112 printk("%s: packet of length %d sent\n", dev->name, (int) skb->len);
1113
1114
1115
1116
1117 dev->trans_start = jiffies;
1118
1119 prime_rx(dev);
1120 spin_unlock_irqrestore(&adapter->lock, flags);
1121 netif_start_queue(dev);
1122 return 0;
1123}
1124
1125
1126
1127
1128
1129
1130
1131static struct net_device_stats *elp_get_stats(struct net_device *dev)
1132{
1133 elp_device *adapter = (elp_device *) dev->priv;
1134
1135 if (elp_debug >= 3)
1136 printk("%s: request for stats\n", dev->name);
1137
1138
1139
1140 if (!netif_running(dev))
1141 return &adapter->stats;
1142
1143
1144 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1145 adapter->tx_pcb.length = 0;
1146 adapter->got[CMD_NETWORK_STATISTICS] = 0;
1147 if (!send_pcb(dev, &adapter->tx_pcb))
1148 printk("%s: couldn't send get statistics command\n", dev->name);
1149 else {
1150 int timeout = jiffies + TIMEOUT;
1151 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout));
1152 if (time_after_eq(jiffies, timeout)) {
1153 TIMEOUT_MSG(__LINE__);
1154 return &adapter->stats;
1155 }
1156 }
1157
1158
1159 return &adapter->stats;
1160}
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
1171{
1172 u32 ethcmd;
1173
1174
1175
1176
1177 if (get_user(ethcmd, (u32 *)useraddr))
1178 return -EFAULT;
1179
1180 switch (ethcmd) {
1181
1182 case ETHTOOL_GDRVINFO: {
1183 struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
1184 strcpy (info.driver, DRV_NAME);
1185 strcpy (info.version, DRV_VERSION);
1186 sprintf(info.bus_info, "ISA 0x%lx", dev->base_addr);
1187 if (copy_to_user (useraddr, &info, sizeof (info)))
1188 return -EFAULT;
1189 return 0;
1190 }
1191
1192
1193 case ETHTOOL_GMSGLVL: {
1194 struct ethtool_value edata = {ETHTOOL_GMSGLVL};
1195 edata.data = debug;
1196 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1197 return -EFAULT;
1198 return 0;
1199 }
1200
1201 case ETHTOOL_SMSGLVL: {
1202 struct ethtool_value edata;
1203 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1204 return -EFAULT;
1205 debug = edata.data;
1206 return 0;
1207 }
1208
1209 default:
1210 break;
1211 }
1212
1213 return -EOPNOTSUPP;
1214}
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1226{
1227 int rc = 0;
1228
1229 switch (cmd) {
1230 case SIOCETHTOOL:
1231 rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
1232 break;
1233
1234 default:
1235 rc = -EOPNOTSUPP;
1236 break;
1237 }
1238
1239 return rc;
1240}
1241
1242
1243
1244
1245
1246
1247
1248
1249static int elp_close(struct net_device *dev)
1250{
1251 elp_device *adapter;
1252
1253 adapter = dev->priv;
1254
1255 if (elp_debug >= 3)
1256 printk("%s: request to close device\n", dev->name);
1257
1258 netif_stop_queue(dev);
1259
1260
1261
1262
1263
1264 (void) elp_get_stats(dev);
1265
1266
1267
1268
1269 outb_control(0, dev);
1270
1271
1272
1273
1274 free_irq(dev->irq, dev);
1275
1276 free_dma(dev->dma);
1277 free_pages((unsigned long) adapter->dma_buffer, get_order(DMA_BUFFER_SIZE));
1278
1279 return 0;
1280}
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292static void elp_set_mc_list(struct net_device *dev)
1293{
1294 elp_device *adapter = (elp_device *) dev->priv;
1295 struct dev_mc_list *dmi = dev->mc_list;
1296 int i;
1297 unsigned long flags;
1298
1299 if (elp_debug >= 3)
1300 printk("%s: request to set multicast list\n", dev->name);
1301
1302 spin_lock_irqsave(&adapter->lock, flags);
1303
1304 if (!(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1305
1306
1307 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1308 adapter->tx_pcb.length = 6 * dev->mc_count;
1309 for (i = 0; i < dev->mc_count; i++) {
1310 memcpy(adapter->tx_pcb.data.multicast[i], dmi->dmi_addr, 6);
1311 dmi = dmi->next;
1312 }
1313 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1314 if (!send_pcb(dev, &adapter->tx_pcb))
1315 printk("%s: couldn't send set_multicast command\n", dev->name);
1316 else {
1317 int timeout = jiffies + TIMEOUT;
1318 while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && time_before(jiffies, timeout));
1319 if (time_after_eq(jiffies, timeout)) {
1320 TIMEOUT_MSG(__LINE__);
1321 }
1322 }
1323 if (dev->mc_count)
1324 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1325 else
1326 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1327 } else
1328 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1329
1330
1331
1332
1333 if (elp_debug >= 3)
1334 printk("%s: sending 82586 configure command\n", dev->name);
1335 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1336 adapter->tx_pcb.length = 2;
1337 adapter->got[CMD_CONFIGURE_82586] = 0;
1338 if (!send_pcb(dev, &adapter->tx_pcb))
1339 {
1340 spin_unlock_irqrestore(&adapter->lock, flags);
1341 printk("%s: couldn't send 82586 configure command\n", dev->name);
1342 }
1343 else {
1344 int timeout = jiffies + TIMEOUT;
1345 spin_unlock_irqrestore(&adapter->lock, flags);
1346 while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout));
1347 if (time_after_eq(jiffies, timeout))
1348 TIMEOUT_MSG(__LINE__);
1349 }
1350}
1351
1352
1353
1354
1355
1356
1357
1358static inline void elp_init(struct net_device *dev)
1359{
1360 elp_device *adapter = dev->priv;
1361
1362
1363
1364
1365 dev->open = elp_open;
1366 dev->stop = elp_close;
1367 dev->get_stats = elp_get_stats;
1368 dev->hard_start_xmit = elp_start_xmit;
1369 dev->tx_timeout = elp_timeout;
1370 dev->watchdog_timeo = 10*HZ;
1371 dev->set_multicast_list = elp_set_mc_list;
1372 dev->do_ioctl = netdev_ioctl;
1373
1374
1375 ether_setup(dev);
1376
1377
1378
1379
1380 memset(&(adapter->stats), 0, sizeof(struct net_device_stats));
1381
1382
1383
1384
1385 dev->mem_start = dev->mem_end = 0;
1386}
1387
1388
1389
1390
1391
1392
1393
1394static int __init elp_sense(struct net_device *dev)
1395{
1396 int timeout;
1397 int addr = dev->base_addr;
1398 const char *name = dev->name;
1399 unsigned long flags;
1400 byte orig_HSR;
1401
1402 if (!request_region(addr, ELP_IO_EXTENT, "3c505"))
1403 return -ENODEV;
1404
1405 orig_HSR = inb_status(addr);
1406
1407 if (elp_debug > 0)
1408 printk(search_msg, name, addr);
1409
1410 if (orig_HSR == 0xff) {
1411 if (elp_debug > 0)
1412 printk(notfound_msg, 1);
1413 goto out;
1414 }
1415
1416 save_flags(flags);
1417 sti();
1418
1419
1420 if (elp_debug > 0)
1421 printk(stilllooking_msg);
1422
1423 if (orig_HSR & DIR) {
1424
1425 outb(0, dev->base_addr + PORT_CONTROL);
1426 timeout = jiffies + 30*HZ/100;
1427 while (time_before(jiffies, timeout));
1428 restore_flags(flags);
1429 if (inb_status(addr) & DIR) {
1430 if (elp_debug > 0)
1431 printk(notfound_msg, 2);
1432 goto out;
1433 }
1434 } else {
1435
1436 outb(DIR, dev->base_addr + PORT_CONTROL);
1437 timeout = jiffies + 30*HZ/100;
1438 while (time_before(jiffies, timeout));
1439 restore_flags(flags);
1440 if (!(inb_status(addr) & DIR)) {
1441 if (elp_debug > 0)
1442 printk(notfound_msg, 3);
1443 goto out;
1444 }
1445 }
1446
1447
1448
1449 if (elp_debug > 0)
1450 printk(found_msg);
1451
1452 return 0;
1453out:
1454 release_region(addr, ELP_IO_EXTENT);
1455 return -ENODEV;
1456}
1457
1458
1459
1460
1461
1462
1463
1464static int __init elp_autodetect(struct net_device *dev)
1465{
1466 int idx = 0;
1467
1468
1469
1470 if (dev->base_addr != 0) {
1471 if (elp_sense(dev) == 0)
1472 return dev->base_addr;
1473 } else
1474 while ((dev->base_addr = addr_list[idx++])) {
1475 if (elp_sense(dev) == 0)
1476 return dev->base_addr;
1477 }
1478
1479
1480 if (elp_debug > 0)
1481 printk(couldnot_msg, dev->name);
1482
1483 return 0;
1484}
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508int __init elplus_probe(struct net_device *dev)
1509{
1510 elp_device *adapter;
1511 int i, tries, tries1, timeout, okay;
1512 unsigned long cookie = 0;
1513
1514 SET_MODULE_OWNER(dev);
1515
1516
1517
1518
1519
1520 dev->base_addr = elp_autodetect(dev);
1521 if (!(dev->base_addr))
1522 return -ENODEV;
1523
1524
1525
1526
1527 adapter = (elp_device *) (dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1528 if (adapter == NULL) {
1529 printk("%s: out of memory\n", dev->name);
1530 return -ENODEV;
1531 }
1532
1533 adapter->send_pcb_semaphore = 0;
1534
1535 for (tries1 = 0; tries1 < 3; tries1++) {
1536 outb_control((adapter->hcr_val | CMDE) & ~DIR, dev);
1537
1538
1539
1540 timeout = jiffies + 5*HZ/100;
1541 okay = 0;
1542 while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE));
1543 if ((inb_status(dev->base_addr) & HCRE)) {
1544 outb_command(0, dev->base_addr);
1545 timeout = jiffies + 5*HZ/100;
1546 while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE));
1547 if (inb_status(dev->base_addr) & HCRE)
1548 okay = 1;
1549 }
1550 if (!okay) {
1551
1552
1553
1554 printk("%s: command register wouldn't drain, ", dev->name);
1555 if ((inb_status(dev->base_addr) & 7) == 3) {
1556
1557
1558
1559 printk("assuming 3c505 still starting\n");
1560 timeout = jiffies + 10*HZ;
1561 while (time_before(jiffies, timeout) && (inb_status(dev->base_addr) & 7));
1562 if (inb_status(dev->base_addr) & 7) {
1563 printk("%s: 3c505 failed to start\n", dev->name);
1564 } else {
1565 okay = 1;
1566 }
1567 } else {
1568
1569
1570
1571 printk("3c505 is sulking\n");
1572 }
1573 }
1574 for (tries = 0; tries < 5 && okay; tries++) {
1575
1576
1577
1578
1579
1580 adapter->tx_pcb.command = CMD_STATION_ADDRESS;
1581 adapter->tx_pcb.length = 0;
1582 cookie = probe_irq_on();
1583 if (!send_pcb(dev, &adapter->tx_pcb)) {
1584 printk("%s: could not send first PCB\n", dev->name);
1585 probe_irq_off(cookie);
1586 continue;
1587 }
1588 if (!receive_pcb(dev, &adapter->rx_pcb)) {
1589 printk("%s: could not read first PCB\n", dev->name);
1590 probe_irq_off(cookie);
1591 continue;
1592 }
1593 if ((adapter->rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1594 (adapter->rx_pcb.length != 6)) {
1595 printk("%s: first PCB wrong (%d, %d)\n", dev->name, adapter->rx_pcb.command, adapter->rx_pcb.length);
1596 probe_irq_off(cookie);
1597 continue;
1598 }
1599 goto okay;
1600 }
1601
1602
1603
1604 printk(KERN_INFO "%s: resetting adapter\n", dev->name);
1605 outb_control(adapter->hcr_val | FLSH | ATTN, dev);
1606 outb_control(adapter->hcr_val & ~(FLSH | ATTN), dev);
1607 }
1608 printk("%s: failed to initialise 3c505\n", dev->name);
1609 release_region(dev->base_addr, ELP_IO_EXTENT);
1610 return -ENODEV;
1611
1612 okay:
1613 if (dev->irq) {
1614 int rpt = probe_irq_off(cookie);
1615 if (dev->irq != rpt) {
1616 printk("%s: warning, irq %d configured but %d detected\n", dev->name, dev->irq, rpt);
1617 }
1618
1619 } else
1620 dev->irq = probe_irq_off(cookie);
1621 switch (dev->irq) {
1622 case 0:
1623 printk("%s: IRQ probe failed: check 3c505 jumpers.\n",
1624 dev->name);
1625 return -ENODEV;
1626 case 1:
1627 case 6:
1628 case 8:
1629 case 13:
1630 printk("%s: Impossible IRQ %d reported by probe_irq_off().\n",
1631 dev->name, dev->irq);
1632 return -ENODEV;
1633 }
1634
1635
1636
1637
1638 outb_control(adapter->hcr_val & ~CMDE, dev);
1639
1640
1641
1642
1643 for (i = 0; i < 6; i++)
1644 dev->dev_addr[i] = adapter->rx_pcb.data.eth_addr[i];
1645
1646
1647 if (!dev->dma) {
1648 if (dev->mem_start) {
1649 dev->dma = dev->mem_start & 7;
1650 }
1651 else {
1652 printk(KERN_WARNING "%s: warning, DMA channel not specified, using default\n", dev->name);
1653 dev->dma = ELP_DMA;
1654 }
1655 }
1656
1657
1658
1659
1660 printk("%s: 3c505 at %#lx, irq %d, dma %d, ",
1661 dev->name, dev->base_addr, dev->irq, dev->dma);
1662 printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
1663 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1664 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1665
1666
1667
1668
1669
1670 adapter->tx_pcb.command = CMD_ADAPTER_INFO;
1671 adapter->tx_pcb.length = 0;
1672 if (!send_pcb(dev, &adapter->tx_pcb) ||
1673 !receive_pcb(dev, &adapter->rx_pcb) ||
1674 (adapter->rx_pcb.command != CMD_ADAPTER_INFO_RESPONSE) ||
1675 (adapter->rx_pcb.length != 10)) {
1676 printk("not responding to second PCB\n");
1677 }
1678 printk("rev %d.%d, %dk\n", adapter->rx_pcb.data.info.major_vers, adapter->rx_pcb.data.info.minor_vers, adapter->rx_pcb.data.info.RAM_sz);
1679
1680
1681
1682
1683 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
1684 adapter->tx_pcb.length = 12;
1685 adapter->tx_pcb.data.memconf.cmd_q = 8;
1686 adapter->tx_pcb.data.memconf.rcv_q = 8;
1687 adapter->tx_pcb.data.memconf.mcast = 10;
1688 adapter->tx_pcb.data.memconf.frame = 10;
1689 adapter->tx_pcb.data.memconf.rcv_b = 10;
1690 adapter->tx_pcb.data.memconf.progs = 0;
1691 if (!send_pcb(dev, &adapter->tx_pcb) ||
1692 !receive_pcb(dev, &adapter->rx_pcb) ||
1693 (adapter->rx_pcb.command != CMD_CONFIGURE_ADAPTER_RESPONSE) ||
1694 (adapter->rx_pcb.length != 2)) {
1695 printk("%s: could not configure adapter memory\n", dev->name);
1696 }
1697 if (adapter->rx_pcb.data.configure) {
1698 printk("%s: adapter configuration failed\n", dev->name);
1699 }
1700
1701
1702
1703
1704 elp_init(dev);
1705
1706 return 0;
1707}
1708
1709#ifdef MODULE
1710static struct net_device dev_3c505[ELP_MAX_CARDS];
1711static int io[ELP_MAX_CARDS];
1712static int irq[ELP_MAX_CARDS];
1713static int dma[ELP_MAX_CARDS];
1714MODULE_PARM(io, "1-" __MODULE_STRING(ELP_MAX_CARDS) "i");
1715MODULE_PARM(irq, "1-" __MODULE_STRING(ELP_MAX_CARDS) "i");
1716MODULE_PARM(dma, "1-" __MODULE_STRING(ELP_MAX_CARDS) "i");
1717MODULE_PARM_DESC(io, "EtherLink Plus I/O base address(es)");
1718MODULE_PARM_DESC(irq, "EtherLink Plus IRQ number(s) (assigned)");
1719MODULE_PARM_DESC(dma, "EtherLink Plus DMA channel(s)");
1720
1721int init_module(void)
1722{
1723 int this_dev, found = 0;
1724
1725 for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) {
1726 struct net_device *dev = &dev_3c505[this_dev];
1727 dev->irq = irq[this_dev];
1728 dev->base_addr = io[this_dev];
1729 dev->init = elplus_probe;
1730 if (dma[this_dev]) {
1731 dev->dma = dma[this_dev];
1732 } else {
1733 dev->dma = ELP_DMA;
1734 printk(KERN_WARNING "3c505.c: warning, using default DMA channel,\n");
1735 }
1736 if (io[this_dev] == 0) {
1737 if (this_dev) break;
1738 printk(KERN_NOTICE "3c505.c: module autoprobe not recommended, give io=xx.\n");
1739 }
1740 if (register_netdev(dev) != 0) {
1741 printk(KERN_WARNING "3c505.c: Failed to register card at 0x%x.\n", io[this_dev]);
1742 if (found != 0) return 0;
1743 return -ENXIO;
1744 }
1745 found++;
1746 }
1747 return 0;
1748}
1749
1750void cleanup_module(void)
1751{
1752 int this_dev;
1753
1754 for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) {
1755 struct net_device *dev = &dev_3c505[this_dev];
1756 if (dev->priv != NULL) {
1757 unregister_netdev(dev);
1758 kfree(dev->priv);
1759 dev->priv = NULL;
1760 release_region(dev->base_addr, ELP_IO_EXTENT);
1761 }
1762 }
1763}
1764
1765#endif
1766MODULE_LICENSE("GPL");
1767