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