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