This source file includes following definitions.
- inb_status
- inb_control
- inb_command
- outb_control
- outb_command
- inw_data
- outw_data
- get_status
- set_hsf
- adapter_reset
- send_pcb_slow
- send_pcb_fast
- prime_rx
- send_pcb
- receive_pcb
- adapter_hard_reset
- start_receive
- receive_packet
- elp_interrupt
- elp_open
- send_packet
- elp_start_xmit
- elp_get_stats
- elp_close
- elp_set_mc_list
- elp_init
- elp_sense
- elp_autodetect
- elplus_probe
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #include <linux/module.h>
38
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/string.h>
42 #include <linux/interrupt.h>
43 #include <linux/ptrace.h>
44 #include <linux/errno.h>
45 #include <linux/in.h>
46 #include <linux/malloc.h>
47 #include <linux/ioport.h>
48 #include <asm/bitops.h>
49 #include <asm/io.h>
50
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/skbuff.h>
54
55 #include "3c505.h"
56
57
58
59
60
61
62
63 static const char * filename = __FILE__;
64
65 static const char * timeout_msg = "*** timeout at %s:%s (line %d) ***\n";
66 #define TIMEOUT_MSG(lineno) \
67 printk(timeout_msg, filename,__FUNCTION__,(lineno))
68
69 static const char * invalid_pcb_msg =
70 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
71 #define INVALID_PCB_MSG(len) \
72 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
73
74 static const char * search_msg = "%s: Looking for 3c505 adapter at address %#x...";
75
76 static const char * stilllooking_msg = "still looking...";
77
78 static const char * found_msg = "found.\n";
79
80 static const char * notfound_msg = "not found (reason = %d)\n";
81
82 static const char * couldnot_msg = "%s: 3c505 not found\n";
83
84
85
86
87
88
89
90 #ifdef ELP_DEBUG
91 static int elp_debug = ELP_DEBUG;
92 #else
93 static int elp_debug = 0;
94 #endif
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 #ifndef TRUE
110 #define TRUE 1
111 #endif
112
113 #ifndef FALSE
114 #define FALSE 0
115 #endif
116
117
118
119
120
121
122
123
124 const int addr_list[]={0x300,0x280,0x310,0};
125
126
127
128
129
130
131
132 static inline unsigned char
133 inb_status (unsigned int base_addr)
134 {
135 return inb(base_addr+PORT_STATUS);
136 }
137
138 static inline unsigned char
139 inb_control (unsigned int base_addr)
140 {
141 return inb(base_addr+PORT_CONTROL);
142 }
143
144 static inline int
145 inb_command (unsigned int base_addr)
146 {
147 return inb(base_addr+PORT_COMMAND);
148 }
149
150 static inline void
151 outb_control (unsigned char val, unsigned int base_addr)
152 {
153 outb(val, base_addr+PORT_CONTROL);
154 }
155
156 static inline void
157 outb_command (unsigned char val, unsigned int base_addr)
158 {
159 outb(val, base_addr+PORT_COMMAND);
160 }
161
162 static inline unsigned int
163 inw_data (unsigned int base_addr)
164 {
165 return inw(base_addr+PORT_DATA);
166 }
167
168 static inline void
169 outw_data (unsigned int val, unsigned int base_addr)
170 {
171 outw(val, base_addr+PORT_DATA);
172 }
173
174
175
176
177
178
179
180
181 typedef struct {
182 volatile short got[NUM_TRANSMIT_CMDS];
183 pcb_struct tx_pcb;
184 pcb_struct rx_pcb;
185 pcb_struct itx_pcb;
186 pcb_struct irx_pcb;
187 struct enet_statistics stats;
188 } elp_device;
189
190 static int reset_count=0;
191
192
193
194
195
196
197
198
199
200
201
202
203
204 #define GET_ASF(addr) \
205 (get_status(addr)&ASF_PCB_MASK)
206
207 static inline int
208 get_status (unsigned int base_addr)
209 {
210 int timeout = jiffies + 10;
211 register int stat1;
212 do {
213 stat1 = inb_status(base_addr);
214 } while (stat1 != inb_status(base_addr) && jiffies < timeout);
215 if (jiffies >= timeout)
216 TIMEOUT_MSG(__LINE__);
217 return stat1;
218 }
219
220 static inline void
221 set_hsf (unsigned int base_addr, int hsf)
222 {
223 cli();
224 outb_control((inb_control(base_addr)&~HSF_PCB_MASK)|hsf, base_addr);
225 sti();
226 }
227
228 static int start_receive (struct device *, pcb_struct *);
229 static void adapter_hard_reset (struct device *);
230
231 inline static void
232 adapter_reset (struct device * dev)
233 {
234 int timeout;
235 unsigned char orig_hcr=inb_control(dev->base_addr);
236
237 elp_device * adapter=dev->priv;
238
239 outb_control(0,dev->base_addr);
240
241 if (inb_status(dev->base_addr)&ACRF) {
242 do {
243 inb_command(dev->base_addr);
244 timeout=jiffies+2;
245 while ((jiffies<=timeout) && !(inb_status(dev->base_addr)&ACRF))
246 ;
247 } while (inb_status(dev->base_addr)&ACRF);
248 set_hsf(dev->base_addr,HSF_PCB_NAK);
249 }
250
251 outb_control(inb_control(dev->base_addr)|ATTN|DIR,dev->base_addr);
252 timeout=jiffies+1;
253 while (jiffies<=timeout)
254 ;
255 outb_control(inb_control(dev->base_addr)&~ATTN,dev->base_addr);
256 timeout=jiffies+1;
257 while (jiffies<=timeout)
258 ;
259 outb_control(inb_control(dev->base_addr)|FLSH,dev->base_addr);
260 timeout=jiffies+1;
261 while (jiffies<=timeout)
262 ;
263 outb_control(inb_control(dev->base_addr)&~FLSH,dev->base_addr);
264 timeout=jiffies+1;
265 while (jiffies<=timeout)
266 ;
267
268 outb_control(orig_hcr, dev->base_addr);
269 if (!start_receive(dev, &adapter->tx_pcb))
270 printk("%s: start receive command failed \n", dev->name);
271 }
272
273
274 static int send_pcb_semaphore = 0;
275 static int rx_restart_needed = 0;
276
277
278 static inline int send_pcb_slow(unsigned int base_addr, unsigned char byte)
279 {
280 int timeout;
281 outb_command(byte, base_addr);
282 for (timeout = jiffies + 5; jiffies < timeout; ) {
283 if (inb_status(base_addr) & HCRE) return FALSE;
284 }
285 printk("3c505: send_pcb_slow timed out\n");
286 return TRUE;
287 }
288
289 static inline int send_pcb_fast(unsigned int base_addr, unsigned char byte)
290 {
291 int timeout;
292 outb_command(byte, base_addr);
293 for (timeout = 0; timeout < 40000; timeout++) {
294 if (inb_status(base_addr) & HCRE) return FALSE;
295 }
296 printk("3c505: send_pcb_fast timed out\n");
297 return TRUE;
298 }
299
300 static int
301 start_receive (struct device * dev, pcb_struct * tx_pcb);
302
303
304 static inline void prime_rx(struct device *dev)
305 {
306 if (rx_restart_needed) {
307 elp_device *adapter = dev->priv;
308 rx_restart_needed = 0;
309 start_receive(dev, &adapter->itx_pcb);
310 }
311 }
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337 static int
338 send_pcb (struct device * dev, pcb_struct * pcb)
339 {
340 int i;
341 int timeout;
342
343
344 if (set_bit(1, &send_pcb_semaphore)) {
345 if (elp_debug >= 3) {
346 printk("%s: send_pcb entered while threaded\n", dev->name);
347 }
348 return FALSE;
349 }
350
351
352
353
354
355
356 set_hsf(dev->base_addr,0);
357
358 if (send_pcb_slow(dev->base_addr, pcb->command)) goto abort;
359
360 cli();
361
362 if (send_pcb_fast(dev->base_addr, pcb->length)) goto sti_abort;
363
364 for (i = 0; i < pcb->length; i++) {
365 if (send_pcb_fast(dev->base_addr, pcb->data.raw[i])) goto sti_abort;
366 }
367
368 outb_control(inb_control(dev->base_addr) | 3, dev->base_addr);
369 outb_command(2+pcb->length, dev->base_addr);
370
371
372 sti();
373
374 for (timeout = jiffies+5; jiffies < timeout; ) {
375 switch (GET_ASF(dev->base_addr)) {
376 case ASF_PCB_ACK:
377 send_pcb_semaphore = 0;
378 if (pcb->command != CMD_TRANSMIT_PACKET) {
379 prime_rx(dev);
380 }
381 return TRUE;
382 break;
383 case ASF_PCB_NAK:
384 printk(KERN_INFO "%s: send_pcb got NAK\n", dev->name);
385 goto abort;
386 break;
387 }
388 }
389
390 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev->name, inb_status(dev->base_addr));
391
392 sti_abort:
393 sti();
394 abort:
395 send_pcb_semaphore = 0;
396 prime_rx(dev);
397 return FALSE;
398 }
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414 static int
415 receive_pcb (struct device * dev, pcb_struct * pcb)
416 {
417 int i, j;
418 int total_length;
419 int stat;
420 int timeout;
421
422 set_hsf(dev->base_addr,0);
423
424
425 timeout = jiffies + 2;
426 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && jiffies < timeout)
427 ;
428 if (jiffies >= timeout) {
429 TIMEOUT_MSG(__LINE__);
430 return FALSE;
431 }
432
433 pcb->command = inb_command(dev->base_addr);
434
435
436 timeout = jiffies + 3;
437 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && jiffies < timeout)
438 ;
439 if (jiffies >= timeout) {
440 TIMEOUT_MSG(__LINE__);
441 printk("%s: status %02x\n", dev->name, stat);
442 return FALSE;
443 }
444 pcb->length = inb_command(dev->base_addr);
445
446 if (pcb->length > MAX_PCB_DATA) {
447 INVALID_PCB_MSG(pcb->length);
448 adapter_reset(dev);
449 return FALSE;
450 }
451
452
453 cli();
454 i = 0;
455 do {
456 j = 0;
457 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && j++ < 20000)
458 ;
459 pcb->data.raw[i++] = inb_command(dev->base_addr);
460 if (i > MAX_PCB_DATA)
461 INVALID_PCB_MSG(i);
462 } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
463 sti();
464 if (j >= 20000) {
465 TIMEOUT_MSG(__LINE__);
466 return FALSE;
467 }
468
469
470 total_length = pcb->data.raw[--i];
471
472
473 if (total_length != (pcb->length + 2)) {
474 if (elp_debug >= 2)
475 printk("%s: mangled PCB received\n", dev->name);
476 set_hsf(dev->base_addr,HSF_PCB_NAK);
477 return FALSE;
478 }
479
480 set_hsf(dev->base_addr,HSF_PCB_ACK);
481 reset_count=0;
482 return TRUE;
483 }
484
485 static void
486 adapter_hard_reset (struct device * dev)
487 {
488 int timeout;
489 long flags;
490
491 save_flags(flags);
492 sti();
493
494 if (elp_debug > 0)
495 printk("%s: Resetting the adapter, please wait (approx 20 s)\n",
496 dev->name);
497
498
499
500 outb_control(ATTN|FLSH, dev->base_addr);
501
502
503
504
505 for (timeout = jiffies + 20; jiffies <= timeout; )
506 ;
507
508
509
510
511 outb_control(0, dev->base_addr);
512
513
514
515
516 for (timeout = jiffies + 20; jiffies <= timeout; )
517 ;
518
519
520
521
522 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
523 if (GET_ASF(dev->base_addr) != ASF_PCB_END)
524 break;
525 restore_flags(flags);
526 }
527
528
529
530
531
532
533
534
535 static int
536 start_receive (struct device * dev, pcb_struct * tx_pcb)
537 {
538 if (elp_debug >= 3)
539 printk("%s: restarting receiver\n", dev->name);
540 tx_pcb->command = CMD_RECEIVE_PACKET;
541 tx_pcb->length = sizeof(struct Rcv_pkt);
542 tx_pcb->data.rcv_pkt.buf_seg
543 = tx_pcb->data.rcv_pkt.buf_ofs = 0;
544 tx_pcb->data.rcv_pkt.buf_len = 1600;
545 tx_pcb->data.rcv_pkt.timeout = 0;
546 return send_pcb(dev, tx_pcb);
547 }
548
549
550
551
552
553
554
555
556
557
558 static void
559 receive_packet (struct device * dev, int len)
560 {
561 register int i;
562 unsigned short * ptr;
563 int timeout;
564 int rlen;
565 struct sk_buff *skb;
566 elp_device * adapter;
567
568 adapter=dev->priv;
569
570 if (len <= 0 || ((len & ~1) != len))
571 if (elp_debug >= 3) {
572 sti();
573 printk("*** bad packet len %d at %s(%d)\n",len,filename,__LINE__);
574 cli();
575 }
576
577 rlen = (len+1) & ~1;
578
579 skb = dev_alloc_skb(rlen+2);
580
581
582
583
584
585 outb_control(inb_control(dev->base_addr)|DIR, dev->base_addr);
586
587
588
589
590 if (skb == NULL) {
591 printk(KERN_INFO "%s: memory squeeze, dropping packet\n", dev->name);
592 for (i = 0; i < (rlen/2); i++) {
593 timeout = 0;
594 while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
595 ;
596 if (timeout >= 20000) {
597 sti();
598 TIMEOUT_MSG(__LINE__);
599 break;
600 }
601
602 inw_data(dev->base_addr);
603 }
604 adapter->stats.rx_dropped++;
605
606 } else {
607 skb_reserve(skb,2);
608 skb->dev = dev;
609
610
611
612
613 ptr = (unsigned short *)skb_put(skb,len);
614 for (i = 0; i < (rlen/2); i++) {
615 timeout = 0;
616 while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
617 ;
618 if (timeout >= 20000) {
619 sti();
620 printk("*** timeout at %s(%d) reading word %d of %d ***\n",
621 filename,__LINE__, i, rlen/2);
622 kfree_skb(skb, FREE_WRITE);
623 return;
624 }
625
626 *ptr = inw_data(dev->base_addr);
627 ptr++;
628 }
629
630 sti();
631 skb->protocol=eth_type_trans(skb,dev);
632 netif_rx(skb);
633 }
634
635 outb_control(inb_control(dev->base_addr)&~DIR, dev->base_addr);
636 }
637
638
639
640
641
642
643
644
645 static void
646 elp_interrupt (int irq, void *dev_id, struct pt_regs *reg_ptr)
647 {
648 int len;
649 int dlen;
650 struct device *dev;
651 elp_device * adapter;
652 int timeout;
653
654 if (irq < 0 || irq > 15) {
655 printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
656 return;
657 }
658
659 dev = irq2dev_map[irq];
660
661 if (dev == NULL) {
662 printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
663 return;
664 }
665
666 adapter = (elp_device *) dev->priv;
667
668 if (dev->interrupt)
669 if (elp_debug >= 2)
670 printk("%s: Re-entering the interrupt handler.\n", dev->name);
671 dev->interrupt = 1;
672
673
674
675
676 sti();
677
678
679
680
681 timeout = jiffies + 3;
682 while ((inb_status(dev->base_addr)&ACRF) != 0 && jiffies < timeout) {
683
684 if (receive_pcb(dev, &adapter->irx_pcb)) {
685
686 switch (adapter->irx_pcb.command) {
687
688
689
690
691 case CMD_RECEIVE_PACKET_COMPLETE:
692
693 if (dev->start == 0)
694 break;
695 cli();
696 len = adapter->irx_pcb.data.rcv_resp.pkt_len;
697 dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
698 if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
699 printk("%s: interrupt - packet not received correctly\n", dev->name);
700 sti();
701 } else {
702 if (elp_debug >= 3) {
703 sti();
704 printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
705 cli();
706 }
707 receive_packet(dev, dlen);
708 sti();
709 if (elp_debug >= 3)
710 printk("%s: packet received\n", dev->name);
711 }
712 if (dev->start && !start_receive(dev, &adapter->itx_pcb)) {
713 if (elp_debug >= 2)
714 printk("%s: interrupt - receiver start deferred\n", dev->name);
715 rx_restart_needed = 1;
716 }
717 if (elp_debug >= 3)
718 printk("%s: receive procedure complete\n", dev->name);
719
720 break;
721
722
723
724
725 case CMD_CONFIGURE_82586_RESPONSE:
726 adapter->got[CMD_CONFIGURE_82586] = 1;
727 if (elp_debug >= 3)
728 printk("%s: interrupt - configure response received\n", dev->name);
729 break;
730
731
732
733
734 case CMD_CONFIGURE_ADAPTER_RESPONSE:
735 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
736 if (elp_debug >= 3)
737 printk("%s: Adapter memory configuration %s.\n",dev->name,
738 adapter->irx_pcb.data.failed?"failed":"succeeded");
739 break;
740
741
742
743
744 case CMD_LOAD_MULTICAST_RESPONSE:
745 adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
746 if (elp_debug >= 3)
747 printk("%s: Multicast address list loading %s.\n",dev->name,
748 adapter->irx_pcb.data.failed?"failed":"succeeded");
749 break;
750
751
752
753
754 case CMD_SET_ADDRESS_RESPONSE:
755 adapter->got[CMD_SET_STATION_ADDRESS] = 1;
756 if (elp_debug >= 3)
757 printk("%s: Ethernet address setting %s.\n",dev->name,
758 adapter->irx_pcb.data.failed?"failed":"succeeded");
759 break;
760
761
762
763
764
765 case CMD_NETWORK_STATISTICS_RESPONSE:
766 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
767 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
768 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
769 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
770 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
771 adapter->got[CMD_NETWORK_STATISTICS] = 1;
772 if (elp_debug >= 3)
773 printk("%s: interrupt - statistics response received\n", dev->name);
774 break;
775
776
777
778
779 case CMD_TRANSMIT_PACKET_COMPLETE:
780 if (elp_debug >= 3)
781 printk("%s: interrupt - packet sent\n", dev->name);
782 if (dev->start == 0)
783 break;
784 if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
785 if (elp_debug >= 2)
786 printk("%s: interrupt - error sending packet %4.4x\n",
787 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
788 dev->tbusy = 0;
789 mark_bh(NET_BH);
790 break;
791
792
793
794
795 default:
796 printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
797 break;
798 }
799 } else {
800 printk("%s: failed to read PCB on interrupt\n", dev->name);
801 adapter_reset(dev);
802 }
803 }
804
805
806
807
808 dev->interrupt = 0;
809 }
810
811
812
813
814
815
816
817
818 static int
819 elp_open (struct device *dev)
820 {
821 elp_device * adapter;
822
823 adapter = dev->priv;
824
825 if (elp_debug >= 3)
826 printk("%s: request to open device\n", dev->name);
827
828
829
830
831 if (adapter == NULL) {
832 printk("%s: Opening a non-existent physical device\n", dev->name);
833 return -EAGAIN;
834 }
835
836
837
838
839 outb_control(0x00, dev->base_addr);
840
841
842
843
844 inb_command(dev->base_addr);
845 adapter_reset(dev);
846
847
848
849
850 dev->interrupt = 0;
851
852
853
854
855 dev->tbusy = 0;
856
857
858
859
860 irq2dev_map[dev->irq] = dev;
861
862
863
864
865 if (request_irq(dev->irq, &elp_interrupt, 0, "3c505", NULL)) {
866 irq2dev_map[dev->irq] = NULL;
867 return -EAGAIN;
868 }
869
870
871
872
873 outb_control(CMDE, dev->base_addr);
874
875
876
877
878 dev->start = 1;
879
880
881
882
883 if (elp_debug >= 3)
884 printk("%s: sending 3c505 memory configuration command\n", dev->name);
885 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
886 adapter->tx_pcb.data.memconf.cmd_q = 10;
887 adapter->tx_pcb.data.memconf.rcv_q = 20;
888 adapter->tx_pcb.data.memconf.mcast = 10;
889 adapter->tx_pcb.data.memconf.frame = 20;
890 adapter->tx_pcb.data.memconf.rcv_b = 20;
891 adapter->tx_pcb.data.memconf.progs = 0;
892 adapter->tx_pcb.length = sizeof(struct Memconf);
893 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
894 if (!send_pcb(dev, &adapter->tx_pcb))
895 printk("%s: couldn't send memory configuration command\n", dev->name);
896 else {
897 int timeout = jiffies + TIMEOUT;
898 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
899 ;
900 if (jiffies >= timeout)
901 TIMEOUT_MSG(__LINE__);
902 }
903
904
905
906
907
908 if (elp_debug >= 3)
909 printk("%s: sending 82586 configure command\n", dev->name);
910 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
911 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
912 adapter->tx_pcb.length = 2;
913 adapter->got[CMD_CONFIGURE_82586] = 0;
914 if (!send_pcb(dev, &adapter->tx_pcb))
915 printk("%s: couldn't send 82586 configure command\n", dev->name);
916 else {
917 int timeout = jiffies + TIMEOUT;
918 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
919 ;
920 if (jiffies >= timeout)
921 TIMEOUT_MSG(__LINE__);
922 }
923
924
925
926
927 if (!start_receive(dev, &adapter->tx_pcb))
928 printk("%s: start receive command failed \n", dev->name);
929 if (!start_receive(dev, &adapter->tx_pcb))
930 printk("%s: start receive command failed \n", dev->name);
931 if (!start_receive(dev, &adapter->tx_pcb))
932 printk("%s: start receive command failed \n", dev->name);
933 if (!start_receive(dev, &adapter->tx_pcb))
934 printk("%s: start receive command failed \n", dev->name);
935 if (elp_debug >= 3)
936 printk("%s: start receive command sent\n", dev->name);
937
938 MOD_INC_USE_COUNT;
939
940 return 0;
941 }
942
943
944
945
946
947
948
949
950 static int
951 send_packet (struct device * dev, unsigned char * ptr, int len)
952 {
953 int i;
954 int timeout = 0;
955 elp_device * adapter;
956
957
958
959
960 unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
961
962 adapter = dev->priv;
963
964 if (nlen < len)
965 printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
966
967
968
969
970
971 adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
972 adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
973 adapter->tx_pcb.data.xmit_pkt.buf_ofs
974 = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0;
975 adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
976 if (!send_pcb(dev, &adapter->tx_pcb)) {
977 return FALSE;
978 }
979
980
981
982
983 cli();
984 for (i = 0; i < (nlen/2);i++) {
985 while (((inb_status(dev->base_addr)&HRDY) == 0)
986 && (timeout++ < 20000))
987 ;
988 if (timeout >= 20000) {
989 sti();
990 printk("%s: timeout at %s(%d) writing word %d of %d ***\n",
991 dev->name,filename,__LINE__, i, nlen/2);
992 return FALSE;
993 }
994
995 outw_data(*(short *)ptr, dev->base_addr);
996 ptr +=2;
997 }
998 sti();
999
1000 prime_rx(dev);
1001
1002 return TRUE;
1003 }
1004
1005
1006
1007
1008
1009
1010
1011
1012 static int
1013 elp_start_xmit (struct sk_buff *skb, struct device *dev)
1014 {
1015
1016
1017
1018 if (dev->tbusy) {
1019 int tickssofar = jiffies - dev->trans_start;
1020 int stat;
1021 if (tickssofar < 40)
1022 return 1;
1023 stat = inb_status(dev->base_addr);
1024 printk("%s: transmit timed out, %s?\n", dev->name, (stat & ACRF)?"IRQ conflict":"network cable problem");
1025 if (elp_debug >= 1)
1026 printk("%s: status %#02x\n", dev->name, stat);
1027 dev->trans_start = jiffies;
1028 dev->tbusy = 0;
1029 }
1030
1031
1032 if (skb == NULL) {
1033 dev_tint(dev);
1034 return 0;
1035 }
1036
1037 if (skb->len <= 0)
1038 return 0;
1039
1040 if (elp_debug >= 3)
1041 printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1042
1043
1044
1045
1046 if (!send_packet(dev, skb->data, skb->len)) {
1047 printk("%s: failed to transmit packet\n", dev->name);
1048 return 1;
1049 }
1050
1051 if (elp_debug >= 3)
1052 printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1053
1054
1055
1056
1057
1058 dev->trans_start = jiffies;
1059
1060
1061
1062
1063 dev->tbusy = 1;
1064
1065
1066
1067
1068 dev_kfree_skb(skb, FREE_WRITE);
1069
1070 return 0;
1071 }
1072
1073
1074
1075
1076
1077
1078
1079 static struct enet_statistics *
1080 elp_get_stats (struct device *dev)
1081 {
1082 elp_device *adapter = (elp_device *) dev->priv;
1083
1084 if (elp_debug >= 3)
1085 printk("%s: request for stats\n", dev->name);
1086
1087
1088
1089 if (!dev->start)
1090 return &adapter->stats;
1091
1092
1093 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1094 adapter->tx_pcb.length = 0;
1095 adapter->got[CMD_NETWORK_STATISTICS] = 0;
1096 if (!send_pcb(dev, &adapter->tx_pcb))
1097 printk("%s: couldn't send get statistics command\n", dev->name);
1098 else {
1099 int timeout = jiffies + TIMEOUT;
1100 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1101 ;
1102 if (jiffies >= timeout) {
1103 TIMEOUT_MSG(__LINE__);
1104 return &adapter->stats;
1105 }
1106 }
1107
1108
1109 return &adapter->stats;
1110 }
1111
1112
1113
1114
1115
1116
1117
1118 static int
1119 elp_close (struct device *dev)
1120 {
1121 elp_device * adapter;
1122
1123 adapter = dev->priv;
1124
1125 if (elp_debug >= 3)
1126 printk("%s: request to close device\n", dev->name);
1127
1128
1129
1130
1131
1132 (void) elp_get_stats(dev);
1133
1134
1135
1136
1137 outb_control(0x00, dev->base_addr);
1138
1139
1140
1141
1142 dev->tbusy = 1;
1143
1144
1145
1146
1147 dev->start = 0;
1148
1149
1150
1151
1152 free_irq(dev->irq, NULL);
1153
1154
1155
1156
1157 irq2dev_map[dev->irq] = 0;
1158
1159 MOD_DEC_USE_COUNT;
1160
1161 return 0;
1162 }
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174 static void
1175 elp_set_mc_list (struct device *dev)
1176 {
1177 elp_device *adapter = (elp_device *) dev->priv;
1178 struct dev_mc_list *dmi=dev->mc_list;
1179 int i;
1180
1181 if (elp_debug >= 3)
1182 printk("%s: request to set multicast list\n", dev->name);
1183
1184 if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI)))
1185 {
1186
1187
1188 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1189 adapter->tx_pcb.length = 6*dev->mc_count;
1190 for (i=0;i<dev->mc_count;i++)
1191 {
1192 memcpy(adapter->tx_pcb.data.multicast[i], dmi->dmi_addr,6);
1193 dmi=dmi->next;
1194 }
1195 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1196 if (!send_pcb(dev, &adapter->tx_pcb))
1197 printk("%s: couldn't send set_multicast command\n", dev->name);
1198 else {
1199 int timeout = jiffies + TIMEOUT;
1200 while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1201 ;
1202 if (jiffies >= timeout) {
1203 TIMEOUT_MSG(__LINE__);
1204 }
1205 }
1206 if (dev->mc_count)
1207 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1208 else
1209 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1210 }
1211 else
1212 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1213
1214
1215
1216
1217 if (elp_debug >= 3)
1218 printk("%s: sending 82586 configure command\n", dev->name);
1219 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1220 adapter->tx_pcb.length = 2;
1221 adapter->got[CMD_CONFIGURE_82586] = 0;
1222 if (!send_pcb(dev, &adapter->tx_pcb))
1223 printk("%s: couldn't send 82586 configure command\n", dev->name);
1224 else {
1225 int timeout = jiffies + TIMEOUT;
1226 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1227 ;
1228 if (jiffies >= timeout)
1229 TIMEOUT_MSG(__LINE__);
1230 }
1231 }
1232
1233
1234
1235
1236
1237
1238
1239 static void
1240 elp_init (struct device *dev)
1241 {
1242 elp_device * adapter;
1243
1244
1245
1246
1247 dev->open = elp_open;
1248 dev->stop = elp_close;
1249 dev->get_stats = elp_get_stats;
1250 dev->hard_start_xmit = elp_start_xmit;
1251 dev->set_multicast_list = elp_set_mc_list;
1252
1253
1254 ether_setup(dev);
1255
1256
1257
1258
1259 adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1260 if (adapter == NULL)
1261 return;
1262 memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1263
1264
1265
1266
1267 dev->mem_start = dev->mem_end = dev->rmem_end = dev->rmem_start = 0;
1268 }
1269
1270
1271
1272
1273
1274
1275
1276 static int
1277 elp_sense (struct device * dev)
1278 {
1279 int timeout;
1280 int addr=dev->base_addr;
1281 const char *name=dev->name;
1282 long flags;
1283 byte orig_HCR, orig_HSR;
1284
1285 if (check_region(addr, 0xf))
1286 return -1;
1287
1288 orig_HCR=inb_control(addr);
1289 orig_HSR=inb_status(addr);
1290
1291 if (elp_debug > 0)
1292 printk(search_msg, name, addr);
1293
1294 if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1295 ((orig_HCR & DIR) != (orig_HSR & DIR))) {
1296 if (elp_debug > 0)
1297 printk(notfound_msg, 1);
1298 return -1;
1299 }
1300
1301
1302 save_flags(flags);
1303 sti();
1304
1305
1306 if (elp_debug > 0)
1307 printk(stilllooking_msg);
1308 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
1309 if (GET_ASF(addr) != ASF_PCB_END)
1310 break;
1311
1312 if (orig_HCR & DIR) {
1313
1314 outb_control(orig_HCR & ~DIR,addr);
1315 timeout = jiffies+30;
1316 while (jiffies < timeout)
1317 ;
1318 restore_flags(flags);
1319 if (inb_status(addr) & DIR) {
1320 outb_control(orig_HCR,addr);
1321 if (elp_debug > 0)
1322 printk(notfound_msg, 2);
1323 return -1;
1324 }
1325 } else {
1326
1327 outb_control(orig_HCR | DIR,addr);
1328 timeout = jiffies+300;
1329 while (jiffies < timeout)
1330 ;
1331 restore_flags(flags);
1332 if (!(inb_status(addr) & DIR)) {
1333 outb_control(orig_HCR,addr);
1334 if (elp_debug > 0)
1335 printk(notfound_msg, 3);
1336 return -1;
1337 }
1338 }
1339
1340
1341
1342
1343 if (elp_debug > 0)
1344 printk(found_msg);
1345
1346 if (((orig_HCR==0x35) && (orig_HSR==0x5b)) || ELP_NEED_HARD_RESET)
1347 adapter_hard_reset(dev);
1348 return 0;
1349 }
1350
1351
1352
1353
1354
1355
1356
1357 static int
1358 elp_autodetect (struct device * dev)
1359 {
1360 int idx=0;
1361
1362
1363
1364 if (dev->base_addr != 0) {
1365 if (elp_sense(dev) == 0)
1366 return dev->base_addr;
1367 } else while ( (dev->base_addr=addr_list[idx++]) ) {
1368 if (elp_sense(dev) == 0)
1369 return dev->base_addr;
1370 }
1371
1372
1373 if (elp_debug > 0)
1374 printk(couldnot_msg, dev->name);
1375
1376 return 0;
1377 }
1378
1379
1380
1381
1382
1383
1384
1385 int
1386 elplus_probe (struct device *dev)
1387 {
1388 elp_device adapter;
1389 int i;
1390
1391
1392
1393
1394
1395 dev->base_addr = elp_autodetect(dev);
1396 if ( !(dev->base_addr) )
1397 return -ENODEV;
1398
1399
1400
1401
1402
1403 outb_control(inb_control(dev->base_addr) | CMDE, dev->base_addr);
1404 autoirq_setup(0);
1405
1406
1407
1408
1409
1410 adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1411 adapter.tx_pcb.length = 0;
1412 if (!send_pcb (dev, &adapter.tx_pcb) ||
1413 !receive_pcb(dev, &adapter.rx_pcb) ||
1414 (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1415 (adapter.rx_pcb.length != 6)) {
1416 printk("%s: not responding to first PCB\n", dev->name);
1417 autoirq_report(0);
1418 return -ENODEV;
1419 }
1420
1421 if (dev->irq) {
1422 if (dev->irq != autoirq_report(0)) {
1423 printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1424 return -ENODEV;
1425 }
1426
1427 } else
1428 dev->irq=autoirq_report(0);
1429 switch (dev->irq) {
1430 case 0:
1431 printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1432 printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1433 return -ENODEV;
1434 case 1:
1435 case 6:
1436 case 8:
1437 case 13:
1438 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1439 dev->name, dev->irq);
1440 return -ENODEV;
1441 }
1442
1443
1444
1445
1446 outb_control(inb_control(dev->base_addr) & ~CMDE, dev->base_addr);
1447
1448
1449
1450
1451 for (i = 0; i < 6; i++)
1452 dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1453
1454
1455
1456
1457 printk("%s: 3c505 card found at I/O %#lx using IRQ%d"
1458 " has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1459 dev->name, dev->base_addr, dev->irq,
1460 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1461 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1462
1463
1464
1465
1466 request_region(dev->base_addr, ELP_IO_EXTENT, "3c505");
1467
1468
1469
1470
1471 elp_init(dev);
1472 return 0;
1473 }
1474
1475 #ifdef MODULE
1476 static char devicename[9] = { 0, };
1477 static struct device dev_3c505 = {
1478 devicename,
1479 0, 0, 0, 0,
1480 0, 0,
1481 0, 0, 0, NULL, elplus_probe };
1482
1483 int io = 0x300;
1484 int irq = 0;
1485
1486 int init_module(void)
1487 {
1488 if (io == 0)
1489 printk("3c505: You should not use auto-probing with insmod!\n");
1490 dev_3c505.base_addr = io;
1491 dev_3c505.irq = irq;
1492 if (register_netdev(&dev_3c505) != 0) {
1493 printk("3c505: register_netdev() returned non-zero.\n");
1494 return -EIO;
1495 }
1496 return 0;
1497 }
1498
1499 void
1500 cleanup_module(void)
1501 {
1502 unregister_netdev(&dev_3c505);
1503 kfree(dev_3c505.priv);
1504 dev_3c505.priv = NULL;
1505
1506
1507 release_region(dev_3c505.base_addr, ELP_IO_EXTENT);
1508 }
1509 #endif