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