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