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 reg_ptr)
669
670 {
671 int len;
672 int dlen;
673 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
674 struct device *dev;
675 elp_device * adapter;
676 int timeout;
677
678 if (irq < 0 || irq > 15) {
679 printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
680 return;
681 }
682
683
684 #if 0
685 if (irq != ELP_IRQ) {
686 printk ("elp_interrupt(): - interrupt routine has incorrect IRQ of %i\n", irq);
687 return;
688 }
689 #endif
690
691 dev = irq2dev_map[irq];
692
693 if (dev == NULL) {
694 printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
695 return;
696 }
697
698 adapter = (elp_device *) dev->priv;
699
700 CHECK_NULL(adapter);
701
702 if (dev->interrupt)
703 if (elp_debug >= 2)
704 printk("%s: Re-entering the interrupt handler.\n", dev->name);
705 dev->interrupt = 1;
706
707
708
709
710 sti();
711
712
713
714
715 timeout = jiffies + TIMEOUT;
716 while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0 &&
717 jiffies < timeout) {
718
719 if (receive_pcb(adapter, &adapter->irx_pcb)) {
720
721 switch (adapter->irx_pcb.command) {
722
723
724
725
726 case CMD_CONFIGURE_82586_RESPONSE:
727 adapter->got[CMD_CONFIGURE_82586] = 1;
728 if (elp_debug >= 3)
729 printk("%s: interrupt - configure response received\n", dev->name);
730 break;
731
732
733
734
735 case CMD_CONFIGURE_ADAPTER_RESPONSE:
736 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
737 if (elp_debug >= 3)
738 printk("%s: Adapter memory configuration %s.",dev->name,
739 adapter->irx_pcb.data.failed?"failed":"succeeded");
740 break;
741
742
743
744
745 case CMD_LOAD_MULTICAST_RESPONSE:
746 adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
747 if (elp_debug >= 3)
748 printk("%s: Multicast address list loading %s.",dev->name,
749 adapter->irx_pcb.data.failed?"failed":"succeeded");
750 break;
751
752
753
754
755 case CMD_SET_ADDRESS_RESPONSE:
756 adapter->got[CMD_SET_STATION_ADDRESS] = 1;
757 if (elp_debug >= 3)
758 printk("%s: Ethernet address setting %s.",dev->name,
759 adapter->irx_pcb.data.failed?"failed":"succeeded");
760 break;
761
762
763
764
765
766 case CMD_NETWORK_STATISTICS_RESPONSE:
767 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
768 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
769 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
770 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
771 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
772 adapter->got[CMD_NETWORK_STATISTICS] = 1;
773 if (elp_debug >= 3)
774 printk("%s: interrupt - statistics response received\n", dev->name);
775 break;
776
777
778
779
780 case CMD_RECEIVE_PACKET_COMPLETE:
781
782 if (dev->start == 0)
783 break;
784 len = adapter->irx_pcb.data.rcv_resp.pkt_len;
785 dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
786 if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
787 printk("%s: interrupt - packet not received correctly\n", dev->name);
788 } else {
789 if (elp_debug >= 3)
790 printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
791 receive_packet(dev, adapter, dlen);
792 if (elp_debug >= 3)
793 printk("%s: packet received\n", dev->name);
794 }
795 if (dev->start && !start_receive(adapter, &adapter->itx_pcb))
796 if (elp_debug >= 2)
797 printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
798 if (elp_debug >= 3)
799 printk("%s: receive procedure complete\n", dev->name);
800
801 break;
802
803
804
805
806 case CMD_TRANSMIT_PACKET_COMPLETE:
807 if (elp_debug >= 3)
808 printk("%s: interrupt - packet sent\n", dev->name);
809 if (dev->start == 0)
810 break;
811 if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
812 if (elp_debug >= 2)
813 printk("%s: interrupt - error sending packet %4.4x\n",
814 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
815 dev->tbusy = 0;
816 #if (ELP_KERNEL_TYPE < 3)
817 mark_bh(INET_BH);
818 #else
819 mark_bh(NET_BH);
820 #endif
821 break;
822
823
824
825
826 default:
827 printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
828 break;
829 }
830 } else
831 printk("%s: failed to read PCB on interrupt\n", dev->name);
832 }
833 if (jiffies >= timeout)
834 TIMEOUT_MSG();
835
836
837
838
839 dev->interrupt = 0;
840 }
841
842
843
844
845
846
847
848
849 static int elp_open (struct device *dev)
850
851 {
852 elp_device * adapter = (elp_device *) dev->priv;
853
854 CHECK_NULL(dev);
855
856 if (elp_debug >= 3)
857 printk("%s: request to open device\n", dev->name);
858
859
860
861
862 if (adapter == NULL) {
863 printk("%s: Opening a non-existent physical device\n", dev->name);
864 return -EAGAIN;
865 }
866
867
868
869
870 OUTB(0x00, adapter->io_addr+PORT_CONTROL);
871
872
873
874
875 INB(adapter->io_addr+PORT_COMMAND);
876
877
878
879
880 dev->interrupt = 0;
881
882
883
884
885 dev->tbusy = 0;
886
887
888
889
890 if (request_irq(dev->irq, &elp_interrupt, 0, "3c505"))
891 return -EAGAIN;
892
893
894
895
896 irq2dev_map[dev->irq] = dev;
897
898
899
900
901 OUTB(CONTROL_CMDE, adapter->io_addr+PORT_CONTROL);
902
903
904
905
906 dev->start = 1;
907
908
909
910
911 if (elp_debug >= 3)
912 printk("%s: sending 3c505 memory configuration command\n", dev->name);
913 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
914 adapter->tx_pcb.data.memconf.cmd_q = 10;
915 adapter->tx_pcb.data.memconf.rcv_q = 20;
916 adapter->tx_pcb.data.memconf.mcast = 10;
917 adapter->tx_pcb.data.memconf.frame = 20;
918 adapter->tx_pcb.data.memconf.rcv_b = 20;
919 adapter->tx_pcb.data.memconf.progs = 0;
920 adapter->tx_pcb.length = sizeof(struct Memconf);
921 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
922 if (!send_pcb(adapter, &adapter->tx_pcb))
923 printk("%s: couldn't send memory configuration command\n", dev->name);
924 else {
925 int timeout = jiffies + TIMEOUT;
926 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
927 ;
928 if (jiffies >= timeout)
929 TIMEOUT_MSG();
930 }
931
932
933
934
935
936 if (elp_debug >= 3)
937 printk("%s: sending 82586 configure command\n", dev->name);
938 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
939 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
940 adapter->tx_pcb.length = 2;
941 adapter->got[CMD_CONFIGURE_82586] = 0;
942 if (!send_pcb(adapter, &adapter->tx_pcb))
943 printk("%s: couldn't send 82586 configure command\n", dev->name);
944 else {
945 int timeout = jiffies + TIMEOUT;
946 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
947 ;
948 if (jiffies >= timeout)
949 TIMEOUT_MSG();
950 }
951
952
953
954
955 if (!start_receive(adapter, &adapter->tx_pcb))
956 printk("%s: start receive command failed \n", dev->name);
957 if (elp_debug >= 3)
958 printk("%s: start receive command sent\n", dev->name);
959
960 return 0;
961 }
962
963
964
965
966
967
968
969
970 static int send_packet (elp_device * adapter, unsigned char * ptr, int len)
971
972 {
973 int i;
974
975
976
977
978 unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
979
980 CHECK_NULL(adapter);
981 CHECK_NULL(ptr);
982
983 if (nlen < len)
984 printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
985
986
987
988
989
990 adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
991 adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
992 adapter->tx_pcb.data.xmit_pkt.buf_ofs = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0;
993 adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
994 if (!send_pcb(adapter, &adapter->tx_pcb))
995 return FALSE;
996
997
998
999
1000 cli();
1001 OUTB(INB(adapter->io_addr+PORT_CONTROL)&(~CONTROL_DIR), adapter->io_addr+PORT_CONTROL);
1002 sti();
1003
1004
1005
1006
1007 for (i = 0; i < (nlen/2);i++) {
1008 int timeout = jiffies + TIMEOUT;
1009 while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0 && jiffies < timeout)
1010 ;
1011 if (jiffies >= timeout) {
1012 printk("*** timeout at %s(%d) writing word %d of %d ***\n",
1013 filename,__LINE__, i, nlen/2);
1014 return FALSE;
1015 }
1016
1017 outw(*(short *)ptr, adapter->io_addr+PORT_DATA);
1018 ptr +=2;
1019 }
1020
1021 return TRUE;
1022 }
1023
1024
1025
1026
1027
1028
1029
1030
1031 static int elp_start_xmit(struct sk_buff *skb, struct device *dev)
1032
1033 {
1034 elp_device * adapter = (elp_device *) dev->priv;
1035
1036 CHECK_NULL(dev);
1037
1038
1039
1040
1041 if (skb == NULL) {
1042 dev_tint(dev);
1043 return 0;
1044 }
1045
1046
1047
1048
1049
1050 #if (ELP_KERNEL_TYPE < 2)
1051 IS_SKB(skb);
1052 if (!skb->arp && dev->rebuild_header(SKB_DATA, dev)) {
1053 skb->dev = dev;
1054 IS_SKB(skb);
1055 arp_queue (skb);
1056 return 0;
1057 }
1058 #endif
1059
1060
1061
1062
1063 if (skb->len <= 0)
1064 return 0;
1065
1066 if (elp_debug >= 3)
1067 printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1068
1069
1070
1071
1072 if (dev->tbusy) {
1073 int tickssofar = jiffies - dev->trans_start;
1074 if (tickssofar < 200)
1075 return 1;
1076 printk("%s: transmit timed out, resetting adapter\n", dev->name);
1077 if ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0)
1078 printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
1079 adapter_reset(adapter);
1080 dev->trans_start = jiffies;
1081 dev->tbusy = 0;
1082 }
1083
1084
1085
1086
1087 if (!send_packet(adapter, (unsigned char *)SKB_DATA, skb->len)) {
1088 printk("%s: send packet PCB failed\n", dev->name);
1089 return 1;
1090 }
1091
1092 if (elp_debug >= 3)
1093 printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1094
1095
1096
1097
1098
1099 dev->trans_start = jiffies;
1100
1101
1102
1103
1104 dev->tbusy = 1;
1105
1106
1107
1108
1109 #if (ELP_KERNEL_TYPE < 4)
1110 if (skb->free)
1111 {
1112 IS_SKB(skb);
1113 kfree_skb(skb, FREE_WRITE);
1114 }
1115 #else
1116 dev_kfree_skb(skb, FREE_WRITE);
1117 #endif
1118
1119 return 0;
1120 }
1121
1122
1123
1124
1125
1126
1127
1128 static struct enet_statistics * elp_get_stats(struct device *dev)
1129
1130 {
1131 elp_device *adapter = (elp_device *) dev->priv;
1132
1133 if (elp_debug >= 3)
1134 printk("%s: request for stats\n", dev->name);
1135
1136
1137
1138 if (!dev->start)
1139 return &adapter->stats;
1140
1141
1142 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1143 adapter->tx_pcb.length = 0;
1144 adapter->got[CMD_NETWORK_STATISTICS] = 0;
1145 if (!send_pcb(adapter, &adapter->tx_pcb))
1146 printk("%s: couldn't send get statistics command\n", dev->name);
1147 else
1148 {
1149 int timeout = jiffies + TIMEOUT;
1150 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1151 ;
1152 if (jiffies >= timeout) {
1153 TIMEOUT_MSG();
1154 return &adapter->stats;
1155 }
1156 }
1157
1158
1159 return &adapter->stats;
1160 }
1161
1162
1163
1164
1165
1166
1167
1168 static int elp_close (struct device *dev)
1169
1170 {
1171 elp_device * adapter = (elp_device *) dev->priv;
1172
1173 CHECK_NULL(dev);
1174 CHECK_NULL(adapter);
1175
1176 if (elp_debug >= 3)
1177 printk("%s: request to close device\n", dev->name);
1178
1179
1180
1181
1182
1183 (void) elp_get_stats(dev);
1184
1185
1186
1187
1188 OUTB(0x00, adapter->io_addr+PORT_CONTROL);
1189
1190
1191
1192
1193 dev->tbusy = 1;
1194
1195
1196
1197
1198 dev->start = 0;
1199
1200
1201
1202
1203 free_irq(dev->irq);
1204
1205
1206
1207
1208 irq2dev_map[dev->irq] = 0;
1209
1210 return 0;
1211 }
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223 static void elp_set_mc_list(struct device *dev, int num_addrs, void *addrs)
1224 {
1225 elp_device *adapter = (elp_device *) dev->priv;
1226 int i;
1227
1228 if (elp_debug >= 3)
1229 printk("%s: request to set multicast list\n", dev->name);
1230
1231 if (num_addrs != -1) {
1232
1233
1234 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1235 adapter->tx_pcb.length = 6*num_addrs;
1236 for (i=0;i<num_addrs;i++)
1237 memcpy(adapter->tx_pcb.data.multicast[i], addrs+6*i,6);
1238 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1239 if (!send_pcb(adapter, &adapter->tx_pcb))
1240 printk("%s: couldn't send set_multicast command\n", dev->name);
1241 else {
1242 int timeout = jiffies + TIMEOUT;
1243 while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1244 ;
1245 if (jiffies >= timeout) {
1246 TIMEOUT_MSG();
1247 }
1248 }
1249 if (num_addrs)
1250 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1251 else
1252 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1253 } else
1254 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_ALL;
1255
1256
1257
1258
1259 if (elp_debug >= 3)
1260 printk("%s: sending 82586 configure command\n", dev->name);
1261 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1262 adapter->tx_pcb.length = 2;
1263 adapter->got[CMD_CONFIGURE_82586] = 0;
1264 if (!send_pcb(adapter, &adapter->tx_pcb))
1265 printk("%s: couldn't send 82586 configure command\n", dev->name);
1266 else {
1267 int timeout = jiffies + TIMEOUT;
1268 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1269 ;
1270 if (jiffies >= timeout)
1271 TIMEOUT_MSG();
1272 }
1273 }
1274
1275
1276
1277
1278
1279
1280
1281 static void elp_init(struct device *dev)
1282
1283 {
1284 elp_device * adapter;
1285
1286 CHECK_NULL(dev);
1287
1288
1289
1290
1291
1292 #if (ELP_KERNEL_TYPE < 2)
1293 {
1294 int i;
1295 for (i = 0; i < DEV_NUMBUFFS; i++)
1296 dev->buffs[i] = NULL;
1297 }
1298 #endif
1299
1300
1301
1302
1303 dev->open = elp_open;
1304 dev->stop = elp_close;
1305 dev->get_stats = elp_get_stats;
1306 dev->hard_start_xmit = elp_start_xmit;
1307 dev->set_multicast_list = elp_set_mc_list;
1308
1309 #if (ELP_KERNEL_TYPE < 2)
1310 dev->hard_header = eth_header;
1311 dev->add_arp = eth_add_arp;
1312 dev->rebuild_header = eth_rebuild_header;
1313 dev->type_trans = eth_type_trans;
1314 dev->queue_xmit = dev_queue_xmit;
1315 #else
1316
1317 ether_setup(dev);
1318 #endif
1319
1320
1321
1322
1323 adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1324 CHECK_NULL(adapter);
1325 adapter->io_addr = dev->base_addr;
1326 adapter->name = dev->name;
1327 memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1328
1329
1330
1331
1332
1333
1334 #if (ELP_KERNEL_TYPE < 2)
1335 dev->type = ARPHRD_ETHER;
1336 dev->hard_header_len = ETH_HLEN;
1337 dev->mtu = 1500;
1338 dev->addr_len = ETH_ALEN;
1339 {
1340 int i;
1341 for (i = 0; i < dev->addr_len; i++)
1342 dev->broadcast[i] = 0xff;
1343 }
1344
1345
1346
1347
1348 dev->flags = IFF_BROADCAST;
1349 dev->family = AF_INET;
1350 dev->pa_addr = 0;
1351 dev->pa_brdaddr = 0;
1352 dev->pa_mask = 0;
1353 dev->pa_alen = sizeof(unsigned long);
1354 #endif
1355
1356
1357
1358
1359 dev->mem_start = dev->mem_end = dev->rmem_end = dev->mem_start = 0;
1360
1361 #if ELP_NEED_HARD_RESET
1362 adapter_hard_reset(adapter);
1363 #else
1364 adapter_reset(adapter);
1365 #endif
1366 }
1367
1368
1369
1370
1371
1372
1373
1374 static int elp_sense(int addr)
1375 {
1376 int timeout;
1377 byte orig_HCR=INB(addr+PORT_CONTROL),
1378 orig_HSR=INB(addr+PORT_STATUS);
1379
1380 if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1381 ( (orig_HCR & CONTROL_DIR) != (orig_HSR & STATUS_DIR) ) )
1382 return 1;
1383
1384
1385 if (elp_debug > 0)
1386 printk(stilllooking_msg);
1387 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
1388 if ((INB(addr+PORT_STATUS) & ASF_PCB_MASK) != ASF_PCB_END)
1389 break;
1390
1391 if (orig_HCR & CONTROL_DIR) {
1392
1393 OUTB(orig_HCR & ~CONTROL_DIR,addr+PORT_CONTROL);
1394 timeout = jiffies+30;
1395 while (jiffies < timeout)
1396 ;
1397 if (INB(addr+PORT_STATUS) & STATUS_DIR) {
1398 OUTB(orig_HCR,addr+PORT_CONTROL);
1399 return 2;
1400 }
1401 } else {
1402
1403 OUTB(orig_HCR | CONTROL_DIR,addr+PORT_CONTROL);
1404 timeout = jiffies+300;
1405 while (jiffies < timeout)
1406 ;
1407 if (!(INB(addr+PORT_STATUS) & STATUS_DIR)) {
1408 OUTB(orig_HCR,addr+PORT_CONTROL);
1409 return 3;
1410 }
1411 }
1412 return 0;
1413 }
1414
1415
1416
1417
1418
1419
1420
1421 static int elp_autodetect(struct device * dev)
1422 {
1423 int idx=0, addr;
1424
1425
1426
1427 if ( (addr=dev->base_addr) ) {
1428 if (elp_debug > 0)
1429 printk(search_msg, dev->name, addr);
1430 if (elp_sense(addr) == 0)
1431 {
1432 if (elp_debug > 0)
1433 printk(found_msg);
1434 return addr;
1435 } else if (elp_debug > 0)
1436 printk(notfound_msg);
1437 } else while ( (addr=addr_list[idx++]) ) {
1438 if (elp_debug > 0)
1439 printk(search_msg, dev->name, addr);
1440 if (elp_sense(addr) == 0) {
1441 if (elp_debug > 0)
1442 printk(found_msg);
1443 return addr;
1444 } else if (elp_debug > 0)
1445 printk(notfound_msg);
1446 }
1447
1448
1449 if (elp_debug == 0)
1450 printk(couldnot_msg, dev->name);
1451 return 0;
1452 }
1453
1454
1455
1456
1457
1458
1459
1460 int elplus_probe(struct device *dev)
1461
1462 {
1463 elp_device adapter;
1464 int i;
1465
1466 CHECK_NULL(dev);
1467
1468
1469
1470
1471
1472 adapter.io_addr = dev->base_addr = elp_autodetect(dev);
1473 if ( !adapter.io_addr )
1474 return -ENODEV;
1475
1476
1477
1478
1479
1480 OUTB(INB(dev->base_addr+PORT_CONTROL) | CONTROL_CMDE,
1481 dev->base_addr+PORT_CONTROL);
1482 autoirq_setup(0);
1483
1484
1485
1486
1487
1488 adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1489 adapter.tx_pcb.length = 0;
1490 if (!send_pcb (&adapter, &adapter.tx_pcb) ||
1491 !receive_pcb(&adapter, &adapter.rx_pcb) ||
1492 (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1493 (adapter.rx_pcb.length != 6)) {
1494 printk("%s: not responding to first PCB\n", dev->name);
1495 return -ENODEV;
1496 }
1497 if (dev->irq) {
1498 if (dev->irq != autoirq_report(0)) {
1499 printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1500 return -ENODEV;
1501 }
1502
1503 } else
1504 dev->irq=autoirq_report(0);
1505 switch (dev->irq) {
1506 case 0: printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1507 printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1508 return -ENODEV;
1509 case 1:
1510 case 6:
1511 case 8:
1512 case 13:
1513 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1514 dev->name,
1515 dev->irq);
1516 return -ENODEV;
1517 }
1518
1519
1520
1521
1522 OUTB(INB(dev->base_addr+PORT_CONTROL) & ~CONTROL_CMDE,
1523 dev->base_addr+PORT_CONTROL);
1524
1525
1526
1527
1528 for (i = 0; i < 6; i++)
1529 dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1530
1531
1532
1533
1534 #if (ELP_KERNEL_TYPE < 2)
1535 printk("%s: 3c505 card found at I/O 0x%x using IRQ%d has address %s\n",
1536 dev->name, dev->base_addr, dev->irq, eth_print(dev->dev_addr));
1537 #else
1538 printk("%s: 3c505 card found at I/O 0x%x using IRQ%d has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1539 dev->name, dev->base_addr, dev->irq,
1540 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1541 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1542 #endif
1543
1544
1545
1546
1547 elp_init(dev);
1548 return 0;
1549 }